Problem with Adodb’s Insert_id function

Asked

Viewed 97 times

1

In my code I perform two insertions using the Adodb 5 library, with the Mysql driver for PHP.

But at certain times occurs the function Insert_ID() return an id (primary key) of a Insert previous to the one at the time, the two Inserts work smoothly, this can happen if the second Insert return a timeout, and he can return a timeout?

Sample Code

// Primeiro Insert
$db->Execute("INSERT INTO table_1 VALUES ('1')");

// Pega o primeiro id
$id_1 = $db->Insert_ID();

// Segundo Insert
$db->Execute("INSERT INTO table_2 VALUES ('1')")

// Pega o segundo id inserido
$id_2 = $db->Insert_ID(); /* Em certos momento pega o ID do primeiro Insert */

1 answer

1

And if you manage your mistakes that way:

include("adodb5/adodb-exceptions.inc.php");
include("adodb5/adodb.inc.php");

$db = NewADOConnection('mysql');
$db->Connect('localhost','root','senha','testdb');

$ok = $db->Execute("INSERT INTO table_1(nome) values('nome nome nome')");
if ($ok) // verifica se deu tudo OK!
{
    echo $db->Insert_ID();
} else {
    var_dump($db->ErrorMsg());
}

$ok = $db->Execute("INSERT INTO table_1(nome) values('nome nome nome')");
if ($ok) // verifica se deu tudo OK!
{
    echo $db->Insert_ID();
} else {
    var_dump($db->ErrorMsg());
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.