MySQL transactions examples in PHP

17. May 2013

MySQL transactions examples in PHP

 

 http://stackoverflow.com/questions/2708237/php-mysql-transactions-examples

mysql_query("SET AUTOCOMMIT=0");
mysql_query("START TRANSACTION");
$a1 = mysql_query("INSERT INTO rarara (l_id) VALUES('1')");
$a2 = mysql_query("INSERT INTO rarara (l_id) VALUES('2')");
if ($a1 and $a2)
{ 
mysql_query("COMMIT"); 
} 
else
{
mysql_query("ROLLBACK"); 
}

MySQL, PHP , ,

How to safely increment MySQL integer field?

17. May 2013

How to safely increment MySQL integer field?

http://stackoverflow.com/questions/2033537/php-mysql-how-to-safely-increment-mysql-integer-field

 

UPDATE table SET field = field +1 WHERE [...];

MySQL ,

MySql Subtract a table from another

16. May 2013

MySql Subtract a table from another

I found this solution on - http://stackoverflow.com/questions/5738240/mysql-subtract-a-table-from-another

To view all rows in A except those in B:

SELECT*FROM A
WHERE(field1, field2,..., fieldN)NOTIN(SELECT*FROM B
);

To actually delete from table A the rows that are in B:

DELETEFROM A
WHERE(field1, field2,..., fieldN)IN(SELECT*FROM B
);

SQL ,