Monday 15 April 2013

mysql - Running multiple queries in PHP insert erroneous values -


I have participated in a problem I've never seen before. The code is very large and there are many sections, so please do not forget me for too much details. The interesting bit is:

  $ copy = clone $ this; $ Copy-> Worker = $ new_workerid; If ($ copy-> mysql_create_row ($ this- & gt; pending)) $ per;   

It runs as expected when I go to the database, then a new entry appears in the table pending.

Every time I run many questions in succession: $ copy = $ $ this; $ Copy-> Worker = $ new_workerid; If ($ copy-> mysql_create_row ($ this- & gt; Pending)) If ($ this-> mysql_delete_row ($ this- & gt; Pending)) If $ ($-> this-> mysql_create_row ($ this- & Gt; cancelled_table); Copy $ per copy;

Then for some inevitable reasons, the wrong ID column is inserted on one of the table. $ Copy- & gt; Mysql_create_row, among other things, does this:

  if ($ con = db_connect ()) {$ res = mysqli_query ($ con, "IN $ IN INSERT $ table (` worker ' , `Time`,` location`, `work`) value ('$ this- & gt; worker', '$ this- & gt; datetime', '$ this- & location;', '$ this- & Gt; work '); ") or error_log (" mysql_create_row error: MySqli_error ($ con)); If ($ res) {$ this- & gt; Contactid = mysqli_insert_id ($ conn); Foreign currency (present as $ $-> $ et) {$ et-> __ set constituted income ($ this-> contracted); If (! $ Et-> mysql_create_row ($ this-> present-table)) {error_log ("contact-> mysql_create_row error: appearance does not create mysql line"); return false; }   

Object method $ att-> gt; The delegation works in the same way through mysql_create_row ($ this- & attendees_table), this is only the INSERT query.

Now this is where things do not make sense: where the new inserted copy is $ Copy-> Picks the correct ID on mysql_create_row, $ et-> Mysql_create_row does not !!! This inserts the old ID; Also, when I get $ at- & gt; I want to echo out queries from mysql_create_row, so this is true (new id) resonates!

But when I go to the actual database, then the old id. It does not fully understand me.

I have tried to create custom __clone () methods, try to make sure that I have copies and are not references (you are php), but it still generates the same error

The problem appears to be consistent with the questions, such as I do not remove or add new, I have no problem.

Delete works fine, and the second inclusion works fine without any errors.

What might possibly MySQLi support for the wrong ID include, while the query stares right? I can only talk about some kind of background / corrupt corruption, but since I have no control over such a thing, I do not even know how to solve the problem.

Att-> Mysql_create_row, I get:

Before the query ID: 305

'INSERT in XXXXXXXX . present ( contactid , title , forenames , alias , relationship < / Code>, gender , age , , ics_number supervised access , left The value ('305', 'Mr', 'Alex', 'Werner', '', 'M', '29 / 08/1981 ',' 0 ',' ',' ' ',' 0 '); '

After query id: 305

But when I actually go to database, the value entered is old ID value (294). The table column is not auto-increment, it is not unique or primary, it is only an integer (11).

What can this be on the earth?

Your problem may be that you get the last inserted line ID to get mysql_last_insert_id are using. As you are inserting multiple rows, it is possible that you can not find the correct ID. Change

mysql_last_insert_id with a select query returns the id of your last entry and see that your problem has been resolved.

No comments:

Post a Comment