在 double 上使用 $wpdb->insert 时我应该使用什么类型的格式?
What type of format should I use when using $wpdb->insert on a double?
我要将 3 条信息存储到我的数据库中:post_id、trans_id 和 trans_amount(金钱)。 trans_id 的一个例子看起来像 9q5fcs
所以我认为我应该使用 %s
作为字符串。我怎样才能将 $wpdb
对象存储 trans_amount 作为双精度对象?
post_id 只是使用相同插入函数时返回的 post id。在此之前,我在另一个代码块中使用它。但是,当我将其格式设置为 %d
时,它不会插入到数据库中。数据库字段设置为 int(11).
代码:
global $wpdb;
$wpdb->insert( $wpdb->prefix . 'fd_transactions', array( 'trans_amount' => $amount), '%s');
$wpdb->insert( $wpdb->prefix . 'fd_transactions', array( 'post_id' => $_SESSION['fd_post_id']), '%d');
$wpdb->insert( $wpdb->prefix . 'fd_transactions', array( 'trans_id' => $trans_id), '%s');
% - a literal percent character. No argument is required.
b - the argument is treated as an integer, and presented as a binary number.
c - the argument is treated as an integer, and presented as the character with that ASCII value.
d - the argument is treated as an integer, and presented as a (signed) decimal number.
e - the argument is treated as scientific notation (e.g. 1.2e+2). The precision specifier stands for the number of digits after the decimal point since PHP 5.2.1. In earlier versions, it was taken as number of significant digits (one less).
E - like %e but uses uppercase letter (e.g. 1.2E+2).
f - the argument is treated as a float, and presented as a floating-point number (locale aware).
F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3.
g - shorter of %e and %f.
G - shorter of %E and %f.
o - the argument is treated as an integer, and presented as an octal number.
s - the argument is treated as and presented as a string.
u - the argument is treated as an integer, and presented as an unsigned decimal number.
x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).
X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).
string s
integer d, u, c, o, x, X, b
double g, G, e, E, f, F
如果不传递数据类型会怎样?
it takes data type as a string
For Double
you can use g, G, e, E, f, F any of these according to your value
我要将 3 条信息存储到我的数据库中:post_id、trans_id 和 trans_amount(金钱)。 trans_id 的一个例子看起来像 9q5fcs
所以我认为我应该使用 %s
作为字符串。我怎样才能将 $wpdb
对象存储 trans_amount 作为双精度对象?
post_id 只是使用相同插入函数时返回的 post id。在此之前,我在另一个代码块中使用它。但是,当我将其格式设置为 %d
时,它不会插入到数据库中。数据库字段设置为 int(11).
代码:
global $wpdb;
$wpdb->insert( $wpdb->prefix . 'fd_transactions', array( 'trans_amount' => $amount), '%s');
$wpdb->insert( $wpdb->prefix . 'fd_transactions', array( 'post_id' => $_SESSION['fd_post_id']), '%d');
$wpdb->insert( $wpdb->prefix . 'fd_transactions', array( 'trans_id' => $trans_id), '%s');
% - a literal percent character. No argument is required.
b - the argument is treated as an integer, and presented as a binary number.
c - the argument is treated as an integer, and presented as the character with that ASCII value.
d - the argument is treated as an integer, and presented as a (signed) decimal number.
e - the argument is treated as scientific notation (e.g. 1.2e+2). The precision specifier stands for the number of digits after the decimal point since PHP 5.2.1. In earlier versions, it was taken as number of significant digits (one less).
E - like %e but uses uppercase letter (e.g. 1.2E+2).
f - the argument is treated as a float, and presented as a floating-point number (locale aware).
F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3.
g - shorter of %e and %f.
G - shorter of %E and %f.
o - the argument is treated as an integer, and presented as an octal number.
s - the argument is treated as and presented as a string.
u - the argument is treated as an integer, and presented as an unsigned decimal number.
x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).
X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).
string s
integer d, u, c, o, x, X, b
double g, G, e, E, f, F
如果不传递数据类型会怎样?
it takes data type as a string
For Double
you can use g, G, e, E, f, F any of these according to your value