ID: 31728 Updated by: [EMAIL PROTECTED] Reported By: godwizard at hotmail dot com -Status: Open +Status: Feedback Bug Type: MySQL related Operating System: Linux Fedora Core 2 PHP Version: 5.0.3 New Comment:
>Here is all code what U will need... I don't need *all* your code, I need only a small reproduce code that doesn't use any external resources (except MySQL, of course). Please, reduce the code, as I'm unable to run it without your session data, functions used, contants etc. etc. Also, provide a table structure dump (you can also provide some sample data). Put in somewhere in the net and post URL here if possible. Previous Comments: ------------------------------------------------------------------------ [2005-01-27 20:50:28] godwizard at hotmail dot com Here is all code what U will need... <?php class DB { var $usr; var $pwd; var $db; var $server; var $query; function open($usr, $pwd, $db, $server) { $this->usr = $usr; $this->pwd = $pwd; $this->db = $db; $this->server = $server; $this->link = mysql_connect($this->server, $this->usr, $this->pwd, new_link); if ( ! $this->link ) die ("SQL server not OnLine"); { mysql_select_db($this->db) or die ("Error while trying to open database."); } } function query($query) { $this->query = $query; $result = mysql_query($this->query, $this->link); return $result; } } class STAT { function ddd_use() { global $db_dur_insert; $query = sprintf(" insert into stat_ddd_use (istuntoID, rotuID, resolution, request, aikaleima) values (%u, %u, %s, %s, %u)", sql_valid($_SESSION['stat']['istuntoID']), sql_valid($_SESSION['rotuID']), sql_valid($_COOKIE['users_resolution']), sql_valid($_SESSION['login_request']), sql_valid(time())); if ( (isset($db_dur_insert)) && (isset($query)) ) { $db_dur_insert->query($query); unset($query); } } } class ADMIN_DOG_SQL { function add_dog() { global $db_dogdata_insert; $aikaleima = time(); if ( (isset($_SESSION['admin']['dog']['rekisteriID'])) && (strlen($_SESSION['admin']['dog']['rekisteriID']) > 0) ) { $query = sprintf(" insert into doginfo_rekisteri_rekisteriID (rekisteriID, oletus, lisatty, lisaaja) values (%s, 1, %u, %u)", sql_valid($_SESSION['admin']['dog']['rekisteriID']), sql_valid($aikaleima), sql_valid($_SESSION['user']['userID'])); if ( (isset($db_dogdata_insert)) && (isset($query)) ) { $result = $db_dogdata_insert->query($query); unset($query); } if ( (isset($result)) && (mysql_affected_rows() > 0) ) { $rekisterinro = mysql_insert_id(); } } } } $db_dogdata_insert = new DB; $db_dogdata_insert->open([parameters]; $db_dur_insert = new DB; $db_dur_insert->open([parameters]; $test1 = new STAT; $test2 = new ADMIN_DOG_SQL; $test1->ddd_use(); // query OK $test2->add_dog(); // query OK but mysql_insert_id returning $test1->ddd_use() insert ID value => making me very mad... ?> ------------------------------------------------------------------------ [2005-01-27 20:38:17] [EMAIL PROTECTED] Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If possible, make the script source available online and provide an URL to it here. Try to avoid embedding huge scripts into the report. ------------------------------------------------------------------------ [2005-01-27 20:24:10] godwizard at hotmail dot com Very odd... The ID which mysql_insert_id is returning, comes from following class/function: function ddd_use() { global $db_dur_insert; $query = sprintf(" insert into stat_ddd_use (istuntoID, rotuID, resolution, request, aikaleima) values (%u, %u, %s, %s, %u)", sql_valid($_SESSION['stat']['istuntoID']), sql_valid($_SESSION['rotuID']), sql_valid($_COOKIE['users_resolution']), sql_valid($_SESSION['login_request']), sql_valid((time()))); if ( (isset($db_dur_insert)) && (isset($query)) ) { $db_dur_insert->query($query); unset($query); } } All code are in several classes. And there is more than 1 DB connection opened at same time. ------------------------------------------------------------------------ [2005-01-27 20:08:22] godwizard at hotmail dot com Description: ------------ mysql_insert_id return wrong ID. It will add new line to DB correctly but when using mysql_insert_id to get auto_increment value, it will return something odd. Reproduce code: --------------- function add_line() { global $db_insert; $aikaleima = time(); if ( (isset($_SESSION['admin']['rekisteriID'])) && (strlen($_SESSION['admin']['rekisteriID']) > 0) ) { $query = sprintf(" insert into rekisteri_rekisteriID (rekisteriID, oletus, lisatty, lisaaja) values (%s, 1, %u, %u)", sql_valid($_SESSION['admin']['rekisteriID']), sql_valid($aikaleima), sql_valid($_SESSION['user']['userID'])); if ( (isset($db_insert)) && (isset($query)) ) { $result = $db_insert->query($query); unset($query); } if ( (isset($result)) && (mysql_affected_rows() > 0) ) { $rekisterinro = mysql_insert_id(); } .... Expected result: ---------------- Example value should be 29171. Actual result: -------------- Value is 7618. And ID 7618 is already reserved in DB. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31728&edit=1