I write code to save data in to the database table.
I want Replace a row in a table if it exists or insert a new row in a table if the row did not already exist.
I use $wpdb->replace
function and then add $wpdb->insert
_id to end of code.
For Update all fields , I using replace 'id' That is primary key.
I add the id field to array
$wpdb->replace( $wpdb->prefix . 'fafa',
array(
'id',
'title' => trim($row->item(0)->nodeValue) ,
'liveprice' => trim($row->item(2)->nodeValue) ,
'changing' => trim($row->item(4)->nodeValue) ,
'lowest' => trim($row->item(6)->nodeValue) ,
'topest' => trim($row->item(8)->nodeValue) ,
'time' => trim($row->item(10)->nodeValue) ),
array(
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
) );
$wpdb->insert_Id;
Aucun commentaire:
Enregistrer un commentaire