Problem with AdoDB Insert_ID function

1

In my code I make two inserts using the Adodb 5 library, with the MySQL driver for PHP.

But at times it happens that the function Insert_ID() returns an id (primary key) of an insert earlier than it does at the moment, the two inserts run smoothly , this can happen if the second insert returns a timeout , and it can return a timeout ?

Example 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 */
    
asked by anonymous 29.08.2014 / 19:09

1 answer

1

And if you handle the errors like this:

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());
}
    
29.08.2014 / 23:58