|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[1999-10-03 06:41 UTC] kara at cvs dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 09:00:02 2025 UTC |
I am writing code to insert a person's ID number and age into a database. The following code gives wacky results! ------------------------------------------- $connection = odbc_connect("mydb","myname","mypassword"); #insert a new age into the database $query="select * from mytable where personID=" . strval($personID) . " and personAge=" . strval($age) . ";"; $result = odbc_exec($connection, $query); odbc_result_all($result,""); #**** $query="insert into mytable(personID, personAge) values (" . strval($personID) . "," . strval($age) . ");"; $result = odbc_exec($connection, $query); ------------------------------------ Establishing the connection works fine. (The same problem occurs with odbc_pconnect.) If I remove everything after the #****, then I get the expected result: -------- No rows found -------- But if I include the lines after the #****, I get the following result (for personID=3 and personAge=50, where these values are not already in the database): -------- PersonID PersonAge 3 50 Warning: SQL error: [Sybase][ODBC Driver]Integrity constraint violation: primary key for table 'mytable' is not unique, SQL state 23000 in SQLExecDirect in makenewaccount on line 45 ---------- Somehow, the "insert" statement is being executed BEFORE the "select" statement is executed, and then the "insert" statement is executed AGAIN. Maybe this is due to some multithreading effect? The data does enter the database successfully. The code behavior described above does not seem to be due to the database itself, because if I enter the exact same commands in a different SQL interpreter on the same database all is well. I am using Win32 PHP 3.0.3 and Apache. --Zeba Kimmel, z-kimmel@uiuc.edu