我在数据库中有一个名为wp_tasks
其中有5个字段。
但我无法将当前时间插入到assign_date
领域
wp_tasks table
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
worker_id INT(6) ,
project_id INT(6),
work_id INT(6),
assign_date DATETIME
Inserting records
function insert_record_to_db( $worker_id, $work_id, $project_id ){
global $wpdb;
$tablename = $wpdb->prefix.\'tasks\';
$data = array(
\'id\' => "",
\'worker_id\' => $worker_id,
\'project_id\' => $project_id,
\'work_id\' => $work_id,
\'assign_date\' => date( "Y-m-d H:i:s" )
);
$format= array( \'%d\', \'%d\', \'%d\',\'%s\');
$wpdb->insert( $tablename, $data, $format );
}
问题是什么?
SO网友:Abubakar Wazih Tushar
试试这个。这应该对你有用
function insert_record_to_db( $worker_id, $work_id, $project_id ){
global $wpdb;
$wpdb->insert(
$wpdb->prefix . \'tasks\',
array(
\'worker_id\' => $worker_id,
\'work_id\' => $work_id,
\'project_id\' => $project_id,
\'assign_date\' => date( \'Y-m-d H:i:s\', current_time(\'timestamp\') )
)
);
// $wpdb->insert_id;
}