Home

Jan 8, 2011

Handy MySQL one-liners


These are just a few MySQL 'one-liners' that I have found useful

One returns the total number of rows in a table.

Another tests the existance of a record

 


Category: MySQL
Posted by: Admin

These are just a few MySQL 'one-liners' that I have found useful

This one returns the total number of rows in a table.


$total = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM items"),0);

 

This one tests the existance of a record


if(mysql_num_rows(mysql_query("SELECT field FROM `table` WHERE field = $row[CLIENT_ID]") ))

{
if record exists --- code here...
}