Database access class for MySql with Php

A php class to access mysql. It uses mysqli How to use: Include this Db file. create a Database object like $db = new Db(); For any query; $sql = ‘Mysql query’; $db->query($aql) $tableObject = new stdClass(); $tableObject->field_name1 = ‘field_value1’ $tableObject->field_name2 = ‘field_value2’ $tableObject->field_name3 = ‘field_value3’ $tableObject->field_name4 = ‘field_value3’ // Insert $db->insertObject(‘table_name’, $tableObject); // Update.

To Find if a record exists or not in MySql

To Find if a record exists or not: Normally we use : SELECT COUNT(*) FROM anj_table WHERE fileldName = ‘anj_field’ Instead use sub-query SELECT EXISTS (SELECT 1 FROM `anj_table` WHERE fieldName = ‘anj-value’ ) It executes faster than SELECT COUNT(*) to get if a particular row exists or not. Reason being sub-query stop executing when