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`(_test name 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("cal l 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_row s;
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 ?
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`(_test name 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("cal l 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_row s;
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 ?
Comment