Re: [請益] 關於 insert_id 的問題

看板PHP作者 ( http://f23ko.com )時間12年前 (2013/09/09 02:32), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《phi12345 (ToRo)》之銘言: : 目前小弟在寫一隻程式 : 想透過 insert_id 這個函式 去取得 insert into 之後 最後一筆的 id 值 : 可是用錯地方 會出現錯誤~ 這是哪的錯誤呢? : $db = new DB(); : $db->connect_db($dbhost, $dbuser, $dbpw, $dbname); : $db->query("SELECT * from cdb_memberfields where fb_id = '$fid'"); : if(empty($result['fb_id'])||$result['fb_id']==null){ : $str="insert into cdb_members (username,password) : values('$usename_fb','$pwd_fb');"; : mysql_query($str,$conn) or die ('Error with MySQL connection'); : $userid = $db->insert_id(); : echo $userid; : } : 會出現 Fatal error: Call to undefined method DB::insert_id() 這個錯誤@@ : 是哪邊用錯了呢? 她找不到$db->insert_id(); 這個function 我沒看過insert_id()這個東西 不過MYSQL可以這樣下sql.... //做完新增之類的動作 SELECT LAST_INSERT_ID(); 然後把第一筆資料抓出來就是最後新稱的id -- 寫做F23,讀做純潔。 二三往事 http://f23ko.com/?ptt -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.35.18.75

09/09 12:14, , 1F
通常在寫好的framework 會統一實做掉
09/09 12:14, 1F
文章代碼(AID): #1IBCAueC (PHP)
討論串 (同標題文章)
文章代碼(AID): #1IBCAueC (PHP)