Piyush Posted February 12, 2010 Share Posted February 12, 2010 My question is like this....my table is like..thisid(auto increment),msg(text),timestamp(number)if an sql insert command is executed...$insert=odbc_exec($connection,"INSERT INTO Data (msg,timestamp) VALUES ('Hi every one',12145478)after executing this command...can i get the id with this...$resultid=odbc_result($insert,"id");will i get the id of the previous record i have just inserted with this method...thanks...waiting for reply... Link to comment Share on other sites More sharing options...
Piyush Posted February 12, 2010 Author Share Posted February 12, 2010 no reply yet... Link to comment Share on other sites More sharing options...
justsomeguy Posted February 12, 2010 Share Posted February 12, 2010 no reply yet...I know it has a large population, but not everyone here lives in India, or even in the same hemisphere.$insert=odbc_exec($connection,"INSERT INTO Data (msg,timestamp) VALUES ('Hi every one',12145478)after executing this command...can i get the id with this...$resultid=odbc_result($insert,"id");That depends, what type of value does odbc_exec return? What type of parameter does odbc_result accept? Have you checked the PHP manual for either of those functions?If odbc_exec returns a result with the new row for an insert query, then yeah that will work. If odbc_exec doesn't return the new row, then that won't work. You should be able to do some testing to figure out what it returns. Link to comment Share on other sites More sharing options...
Piyush Posted February 13, 2010 Author Share Posted February 13, 2010 <?php$con=odbc_connect('Access','','');$sql="INSERT INTO test (msg,ts) VALUES ('Hello world',".time().")";echo $sql;$insert=odbc_exec($con,$sql);echo "get what inserted----";echo odbc_result($insert,"id");?>i tried this but i got an error...No tuples available at this result index in C:\Inetpub\wwwroot\test.php on line 7odbc_exec return result resource...only for Select and related commands... Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2010 Share Posted February 16, 2010 odbc_exec return result resource...only for Select and related commands...Then it sounds like it's not going to return a result resource, so you wouldn't be able to use the return value with odbc_result. Check the documentation for your database to see if you can send a specific query to get the last inserted ID. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.