Description
PDOModel execute query function provides a way to execute any type of query.
It is specifically designed to handle queries if you are not able to run it using other script functions available. While
using this, you can still use the PDO Data binding feature by specifying ? in place of value and passing value
as array. Execute query takes first parameter as query and second parameter is optional where you can speficy
value.
Function Defination
void function executeQuery($sql, $values = array());
Parameters Details
| Details | Type | Example |
|---|---|---|
| $sql - Query to be executed | string | Any valid query e.g. "select * from tablename" |
Examples
$pdomodel = new PDOModel(); //create object of the PDOModel class
$pdomodel->connect("localhost", "root", "", "pdocrud");//connect to database
/* Execute Query function */
$records = $pdomodel->executeQuery("select * from `emp`");
More Examples
//Example 1
$result = $pdomodel->executeQuery("select * from emp where empId = ?", array(39));
Result/Output
Array will be returned in case of select queries else records will be insert/updated/deleted depending upon query.
Debug
| Option | Details | Example |
|---|---|---|
| $pdomodel->getLastQuery(); | Return last query executed | select * from emp where empId = ? |
| print_r($pdomodel->error) | Print errors (if any) | |
| $pdomodel->totalRows; | Total rows returned for select query | 10 |