Updating mysql php

If you omit the WHERE clause, all records will be updated!To learn more about SQL, please visit our SQL tutorial.This is is on PHP Version 5.2.0Hope that this was helpfull for somebody SCENARIO1. You have table t2 linked to table t1 by a CASCADE ON DELETE foreign key.3.t2 has a UNIQUE key so that duplicate records are unacceptable.3.CAUSEWhen the first query (the REPLACE query) deletes a record from t1 in the first stage of the REPLACE operation, it cascades the delete to the record that would be duplicated in t2.The second query then does not fail because the "duplicate" record is no longer a duplicate, as the original one has just been deleted. ON DUPLICATE KEY UPDATE" syntax, mysql_affected_rows() will return you 2 if the UPDATE was made (just as it does with the "REPLACE INTO" syntax) and 1 if the INSERT was.

This creates the possibility that may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.

So if you use one SQL request to insert several rows at a time, and some are inserted, some are just updated, you won't get the real count.

calling mysql_affected_rows(null)is not the same that calling mysql_affected_rows()So, if you have a $link variable that could be null, you must writeif($link) $n=mysql_affected_rows($link);else $n=mysql_affected_rows(); It works also for REPLACE query,returning:0 if the record it's already updated (0 record modified),1 if the record it's new (1 record inserted),2 if the record it's updated (2 operations: 1 deletion 1 insertion) Here's a little function I've been using for a while now, pass it two parameters (action command (1 or 0 see notes)) and a sql statement.

Example output: [0.072][1][80]: UPDATE MYTABLE SET FIELD = 1; [0.106][1][758]: UPDATE ANOTHERTABLE SET FIELD = 2; [0.006][-1][0]: UPDATER ANOTHERTABLE SET FIELD = 2; The output shows: [Timetaken][result[lines affected] The result will be either -1, 0 or 1, -1 means there's a problem with the sql statement, 1 means it executed correctly, 0 means it wasn't executed.

In the case of INSERT where a row/slot had been previously deleted, making an uncollapsed hole in the table, and the record being inserted fills that empty row/slot, that is to say, the inserted data did not create a new row/slot/space, then this may explain why a zero result is returned by this function.

||

This creates the possibility that may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.So if you use one SQL request to insert several rows at a time, and some are inserted, some are just updated, you won't get the real count.calling mysql_affected_rows(null)is not the same that calling mysql_affected_rows()So, if you have a $link variable that could be null, you must writeif($link) $n=mysql_affected_rows($link);else $n=mysql_affected_rows(); It works also for REPLACE query,returning:0 if the record it's already updated (0 record modified),1 if the record it's new (1 record inserted),2 if the record it's updated (2 operations: 1 deletion 1 insertion) Here's a little function I've been using for a while now, pass it two parameters (action command (1 or 0 see notes)) and a sql statement.Example output: [0.072][1][80]: UPDATE MYTABLE SET FIELD = 1; [0.106][1][758]: UPDATE ANOTHERTABLE SET FIELD = 2; [0.006][-1][0]: UPDATER ANOTHERTABLE SET FIELD = 2; The output shows: [Timetaken][result]][lines affected] The result will be either -1, 0 or 1, -1 means there's a problem with the sql statement, 1 means it executed correctly, 0 means it wasn't executed.In the case of INSERT where a row/slot had been previously deleted, making an uncollapsed hole in the table, and the record being inserted fills that empty row/slot, that is to say, the inserted data did not create a new row/slot/space, then this may explain why a zero result is returned by this function.

]]

Search for updating mysql php:

updating mysql php-35

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “updating mysql php”

  1. Mit unseren Leistungen sorgen wir für den nachhaltigen Erfolg Ihrer Windparks: Verlassen Sie sich auf Expertenleistung, technische Professionalität und kompetente Ansprechpartner. Wir haben die Meinungsführer in der Region zu kulturellen, politischen, gesellschaftlichen und wirtschaftlichen Themen befragt.

  2. We have so much info via books and magazines like Alter Ego on the US Golden Age but the UK Golden Age seems to have been forgotten. Reader, et al were the life blood of the UK GA and I was very depressed to have some scanarama and Spacevoucher members say they never considered these publishers or their books worth noting.