php插入mysql数据返回id的方法
发布:smiling 来源: PHP粉丝网 添加日期:2021-09-23 16:46:30 浏览: 评论:0
今天小编就为大家分享一篇php插入mysql数据返回id的方法,具有很好的参考价值,希望对大家有所帮助,一起跟随小编过来看看吧。
如下所示:
- <?php
- $dbh = mysql_connect('localhost','root','root');
- mysql_select_db('pkbk');
- $query = "insert intov9_admin_role_priv(roleid, m, c, a, `data`, siteid) values (12, 'huiben','huiben', 'hbprop_add', '', 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];
- ?>
匹克系统应用:
- $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, 'lbg','9f575f22246a1a5fb38e1846bb0ec964', 'pTseba', '', 1384397338, 1403544894,'221.199.6.231', '118.112.20.103', 0, '', 0, 'nxnet123@qq.com', 2, 0, 0, 0, 10,0, 0, 0, 0, 1, 'A74EECDFA5A22C81C05ED49E7CF9224D', 'qq', '', '', '', 0, 0, '',0, 0, 0, 0)";
- $number=$mydb->sql_query($query);
- echo "ID of last inserted recordis: ".mysql_insert_id();
Tags: php插入mysql数据
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)