Description
PDOModel delete function provides a simplest way to delete the data from database.
You need to pass table name from which you need to delete data and specify where condition to select records to be deleted. Please note that you must set where
condition to delete specific data else all data will be deleted.
Function Defination
void function delete($dbTableName);
Parameters Details
| Details | Type | Example |
|---|---|---|
| $dbTableName - Table name to delete records | string | Any table name like "orderTable", "wp_posts" etc |
Examples
$pdomodel = new PDOModel(); //create object of the PDOModel class
$pdomodel->connect("localhost", "root", "", "pdocrud");//connect to database
/* Delete function */
$pdomodel->where("orderId", 7);//setting where condition
$pdomodel->delete("order");
More Examples
//Example 1
$pdomodel->where("orderId", 7);
$pdomodel->delete("order");
//Example 2
$pdomodel->where("firstName", 'john');
$pdomodel->where("lastName", 'johny');
$pdomodel->delete("emp");
Result/Output
Record will be deleted in database
Debug
| Option | Details | Example |
|---|---|---|
| $pdomodel->getLastQuery(); | Return last query executed | DELETE FROM `emp` WHERE `firstName`= ? AND `lastName`= ? |
| print_r($pdomodel->error) | Print errors (if any) | |
| $pdomodel->rowsChanged; | Return Rows created/changed | 1 |