Home > database >  Consult table insert more problems
Consult table insert more problems

Time:09-29

 & lt; ? PHP 
$dbhost='127.0.0.1:3306;//mysql server host address
$dbuser='003';//mysql user name
$dbpass='003';//mysql user name password
$conn=mysqli_connect ($dbhost, $dbuser, $dbpass);
if(! $conn)
{
Die (' connection fails: '. The mysqli_error ($conn));
}

Mysqli_query ($conn, "set names utf8");//set the coding to prevent Chinese garbled
Mysqli_select_db ($conn, '003');//
Mysqli_query ($conn, "SET the AUTOCOMMIT=0");//set to not submit automatically, because MYSQL default executed immediately
Mysqli_begin_transaction ($conn);//transaction definition
$time=date (' Y -m - d H: I: s');

if(! mysqli_query($conn, "INSERT INTO `003`.`wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (NULL, '1', '$time', '$time', 'neirong1111', 'biaoti1111', '', 'publish', 'open', 'open', '', '', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', '0', '', '0', 'post', '', '0');" ))
{
Mysqli_query ($conn, "ROLLBACK");//determine when failure rollback
}


if(! Mysqli_query ($conn, "INSERT INTO ` 003 `. ` wp_term_relationships ` (` object_id `, ` term_taxonomy_id `, ` term_order `) VALUES (' 15 ', '2', '0');" ))
{
Mysqli_query ($conn, "ROLLBACK");//judgment on failure rollback
}



Mysqli_commit ($conn);//execute transaction
Mysqli_close ($conn);
?>


I'm in the local test WordPress blog, only insert wp_posts table, will be a problem, however, an article WordPress to associate three tables, use the custom fields, need to link the two tables, namely the above situation,
Wp_term_relationships exterior-interior object_id is above wp_posts list ID, this ID is increased, but there are may be interrupted by other things, is not straight, but it doesn't matter, when inserted into the setting value, can be normal since,
Problem now is that want to insert wp_posts table at the same time, also insert wp_term_relationships this table, how to write ah==
Just contact, the search key words all don't know what to search, good fan...

CodePudding user response:

Use the select last_insert_id () to obtain wp_posts insert id value, then wp_term_relationships insert on the value,

CodePudding user response:

reference 1st floor vc555 response:
using the select last_insert_id () to obtain wp_posts insert id value, then wp_term_relationships insert on the value,

  • Related