Home >Backend Development >PHP Tutorial >How to insert mysql data in php and return id

How to insert mysql data in php and return id

不言
不言Original
2018-05-31 15:40:453258browse

This article mainly introduces the method of inserting MySQL data into PHP and returning ID. It has a certain reference value. Now I share it with you. Friends in need can refer to it

as follows Shown:

<?php
$dbh = mysql_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;root&#39;);
mysql_select_db(&#39;pkbk&#39;);
$query = "insert intov9_admin_role_priv(roleid, m, c, a, `data`, siteid) values (12, &#39;huiben&#39;,&#39;huiben&#39;, &#39;hbprop_add&#39;, &#39;&#39;, 1)";
$res = mysql_query($query, $dbh);
//"获取刚才插入的id,表需要设置主键自增"
echo "ID of last inserted record is: " .mysql_insert_id();
$query = "select max(roleid) fromv9_admin_role_priv";
$res = mysql_query($query, $dbh);
$err = mysql_error();
if($err){
  echo "发生错误,请通知管理员";
}
$row = mysql_fetch_row($res);
echo "未来您使用的号码为:".$row[0];
?>

Peak system application:

 $query = " INSERT INTOpkbk.v9_member (phpssouid, username, password, encrypt, nickname, regdate,lastdate, regip, lastip, loginnum, biaoshi, planid, email, groupid, areaid,amount, point, modelid, message, islock, vip, overduedate, siteid, connectid,`from`, mobile, yey, yeybj, sleeptime, waketime, cardno, zentime, zencount,is_js, bsount)".
"VALUES (1, &#39;lbg&#39;,&#39;9f575f22246a1a5fb38e1846bb0ec964&#39;, &#39;pTseba&#39;, &#39;&#39;, 1384397338, 1403544894,&#39;221.199.6.231&#39;, &#39;118.112.20.103&#39;, 0, &#39;&#39;, 0, &#39;nxnet123@qq.com&#39;, 2, 0, 0, 0, 10,0, 0, 0, 0, 1, &#39;A74EECDFA5A22C81C05ED49E7CF9224D&#39;, &#39;qq&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, 0, 0, &#39;&#39;,0, 0, 0, 0)";
    $number=$mydb->sql_query($query);
    echo "ID of last inserted recordis: ".mysql_insert_id();

The above is the entire content of this article, thank you for reading. For more information, please pay attention to the PHP Chinese website!

Related recommendations:

How to get the id of the data just inserted in php

##

The above is the detailed content of How to insert mysql data in php and return id. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn