我想在我的列的时间戳列中插入一个时间戳,但我总是得到全零。
下面是我的插图:
$now = 'NOW()';
// insert the date into the db
$wpdb->insert(
'wp_date',
array(
'name' => $name,
'date' => $now
),
array(
'%s',
'%s'
)
); // end insert发布于 2014-07-20 19:28:27
尝试使用current_time,如下所示(我认为这是一个很好的替代方案):
$now = current_time('mysql');
// insert the date into the db
$wpdb->insert(
'wp_date',
array(
'name' => $name,
'date' => $now
),
array(
'%s',
'%s'
)
); // end insert因此,current_time参数" mysql“表示使用mysql时间戳格式。
发布于 2017-02-07 16:33:28
函数current_time('mysql');返回博客的时间,而不是mysql服务器的时间。要获取Mysql服务器的时间,请执行以下操作。
global $wpdb;
$row = $wpdb->get_row('SELECT now() as now');
// insert the date into the db
$wpdb->insert(
'wp_date',
array(
'name' => $name,
'date' => $row->now
),
array(
'%s',
'%s'
)
)所以就像是..。
$mysql_time = $row->now;
$php_time = date('Y-m-d G:i:s');
$blog_time = current_time('mysql');https://stackoverflow.com/questions/24849977
复制相似问题