views:

93

answers:

1

How can I return a declared string like ( lastInsertId ) from my MySQL stored procedure and out? It's really annoying I can't return error messegts, complate messages and more out to my code in PHP5.

I hope somebody can help me here, I have search Google around without luck :(

Thanks to everybody.

+1  A: 

Hi...

The function you need is mysqli->insert_id

This is the example that php.net provides, I think this function is what you are looking for:

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$mysqli->query("CREATE TABLE myCity LIKE City");

$query = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart', 617000)";
$mysqli->query($query);

printf ("New Record has id %d.\n", $mysqli->insert_id);

/* drop table */
$mysqli->query("DROP TABLE myCity");

/* close connection */
$mysqli->close();
?>

You'll find more info here: php.net: mysqli->inert_id - Manual

If you need more help using it I'll be happy to help you.

Luis