You are here: Is this a bug ? « All PHP « IT news, forums, messages
Is this a bug ?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация