PHP:Does mysql_query("INSERT... return something useful?

brutfood

Registered
I writing some PHP doing stuff to a database, in which I have a table like this...

CREATE TABLE MYTABLE (
something TINYTEXT,
another VARCHAR(16),

created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
userID INT NOT NULL AUTO_INCREMENT,

PRIMARY KEY (userID),

);

And I write some PHP like this...

$sql_result=mysql_query("INSERT INTO MYTABLE VALUES ('hello','world');");

Will $sql_result hold anything useful for an INSERT statement?

Like the record I just inserted? (So $sql_result is an array of records with length 1 - provided everything works).

That would be really useful to me, because I'd like to obtain the userID value, right after the insert, without going through a second query.
 
No, PHP's mysql_query returns either TRUE for success or FALSE on fail. If you need to do two thing (both INSERT the row and SELECT the new userID) at once, you might like to use stored procedures. I have coded some stored procedures, but on Oracle, so I cannot help you more, sorry.
 
Back
Top