Updating a row in sql using php
Another gripe I have about PDO is its inability to get the value of output parameters from stored procedures in some DBMSs, such as SQL Server. My SQL does not seem to return anything in row Count for a select statement, but you can easily and efficiently get the row count as follows:class db extends PDO $my Db = new db('mysql:host=myhost;dbname=mydb', 'login', 'password' ); Then, after running your query:if ( $my Db-My results:-------------------PDO_MSSQLrow Count() Standart: 0row Count() New: 0MSSQL throw PDO_ODBCrow Count() Standart: -1row Count() New: 53MS SQL driver 2.0row Count() Standart: -1row Count() New: 53-------------------With my PDO class you can use prepared queries like: every good work If you use "INSERT INTO ...
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.
When updating a Mysql table with identical values nothing's really affected so row Count will return 0. Perl below noted this is not always preferred behaviour and you can change it yourself since PHP 5.3.
However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.
ON DUPLICATE KEY UPDATE statement is not an INSERT statement, row Count won't return the number or rows inserted or updated for such a statement.
For My SQL, it will return 1 if the row is inserted, and 2 if it is updated, but that may not apply to other databases.fetch All()), which seems like a ridiculous waste of overhead and programming time.
If more than one row responds to the SELECT query, the query returns still only one row and you don't know which one exactly .
Maybe using a SORT BY, would make it a bit more predictible (as in: "if more than one users found, return the last user added in the table") but it's more a matter of good design of the program that fills in the table initially.
Search for updating a row in sql using php:
At 2560 rows inserted, the single query approach consumed ~800kb in memory, while the loop consumed just ~60kb.