mysql - Using select last_insert_id() from php not working -


i have this exact same issue, answer old, , i've read other places use of mysql_insert_id() depreciated , should avoided in new code.

the database innodb , primary key table set auto_increment.

can see i'm doing wrong here? should note i'm beginner , learning on own, apologize glaringly obvious.

$query  = "insert venues (province,city,venue)" . "values " . "('$province','$city','$venue')"; $result = $db->query($query); if ($result) {     echo "$result row(s) sucessfully inserted.<br/>"; } else {     echo "$db->error<br/>"; }  $result = $db->query("select last_insert_id()"); echo $result->num_rows //returns 1 echo $result; //nothing beyond line happens 

update: using mysqli.

the correct way last inserted id, when using mysql_* make call mysql_insert_id().

what reading partially correct - mysql_insert_id in process of being deprecated, it's not function. mysql_* functions being deprecated. instead should use either pdo or mysqli_*.

in code snippet, unclear database access library using. since calls seem bound object, using pdo or mysqli.

for pdo can use pdo::lastinsertid.
mysqli, use mysqli->insert_id.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -