|
Posted by McHenry on 05/03/06 04:37
I am trying to add a new row to a MySQL table using a stored procedure and
then obtain the new id value. The rows are added and affected _rows returns
1 confirming the statement worked however no insert_id value is returned.
The results of running this script are:
New ID:0 New Rows:1
MySQL Code
==============================================
CREATE TABLE testing (
testid INT AUTO_INCREMENT PRIMARY KEY,
testname VARCHAR(25)
)
CREATE PROCEDURE `addtest`(_testname VARCHAR(25))
INSERT INTO testing (testname) VALUES (_testname)
PHP Code
==============================================
<?php
$testname = "McHenry";
//Open the connection
$mysqli = new mysqli("**********", "**********", "**********",
"**********");
// create the statement
$stmt = $mysqli->prepare("call addtest(?)");
/* bind parameters for markers */
$stmt->bind_param("s", $testname);
/* execute query */
$stmt->execute();
//Return the status of the query and display
$newid=$mysqli->insert_id;
$affected_rows=$stmt->affected_rows;
Echo "New ID:$newid New Rows:$affected_rows";
/* close statement */
$stmt->close();
/* close connection */
$mysqli->close();
?>
Thanks in advance...
p.s. If this is a bug is it treated like a new comet etc, do they name it
after you ?
Navigation:
[Reply to this message]
|