- mercromina responded to »error when i try to upgrade to the last version of dizkus module (3.1)« 08:01 PM
- craigh responded to »TagIt 3.0 for Zikula« 03:58 PM
- localrags responded to »Remove contents of nuke_sc_anticracker from Database« 11:30 AM
- jmvaughn responded to »Shoutit for zikula 1.3?« 09:31 AM
- mdee responded to »Different page content under one template (tpl file) based on URL« 07:17 AM
- espaan responded to »Categories disappear when editing ...« 08. Feb
- eledril responded to »How decrease zikula cpu usage« 08. Feb
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Wiki » DeleteOperations
Additions
deleteObject uses the $object to build a where clause. This is useful because one can simple parse an object directly from an input form for example to be deleted. No need to build any where clauses (and have to use pnTables).
NOTE You cannot specify an object *and* and where clause together, one must be blank. To use a where clause you should use pnTables and make object an empty array.
This function allows us to create a custom where clause. Remember to use pnTables to get the correct column names:
Deletions
deleteObject uses the $object to build a where clause. This is useful because one can simple parse an object directly from an input form for example to be deleted. No need to build any where clauses (and have to use pnTables).
NOTE You cannot specify an object *and* and where clause together, one must be blank. To use a where clause you should use pnTables and make object an empty array.
This function allows us to create a custom where clause. Remember to use pnTables to get the correct column names:
Delete Operations
deleteObjectByID
/**
* Delete an object by its ID.
*
* @param tablename The tablename key for the PNTables structure
* @param id The ID of the object to delete
* @param idcolumn The column which contains the ID field (optional) (default='id')
*
* @return The result from the delete operation
*/
function deleteObjectByID ($tablename, $id, $idcolumn='id')
* Delete an object by its ID.
*
* @param tablename The tablename key for the PNTables structure
* @param id The ID of the object to delete
* @param idcolumn The column which contains the ID field (optional) (default='id')
*
* @return The result from the delete operation
*/
function deleteObjectByID ($tablename, $id, $idcolumn='id')
deleteObjectByID ($tablename, $id, $idcolumn='id')
This function will delete one row in the database by the id field. Two examples:
DBUtil::deleteObjectById ('mytable', 4);
DBUtil::deleteObjectById ('customers', $customerid, 'cust_id');
DBUtil::deleteObjectById ('customers', $customerid, 'cust_id');
We can also cheat a little with something like this:
DBUtil::deleteObjectById ('customers', 'USA', 'country');
This would delete multiple rows since the ID field specified is no unique. This provides a nice little shortcut.
deleteObject
/**
* Generate and execute a delete SQL statement for the given object
*
* @param object The object we wish to update
* @param tablename The tablename key for the PNTables structure
* @param where The where clause to use (optional) (default='')
* @param idcolumn The column which contains the ID field (optional) (default='id')
*
* @return The result from the delete operation
*/
function deleteObject ($object, $tablename, $where='', $idcolumn='id')
* Generate and execute a delete SQL statement for the given object
*
* @param object The object we wish to update
* @param tablename The tablename key for the PNTables structure
* @param where The where clause to use (optional) (default='')
* @param idcolumn The column which contains the ID field (optional) (default='id')
*
* @return The result from the delete operation
*/
function deleteObject ($object, $tablename, $where='', $idcolumn='id')
deleteObject ($object, $tablename, $where='', $idcolumn='')
deleteObject uses the $object to build a where clause. This is useful because one can simple parse an object directly from an input form for example to be deleted. No need to build any where clauses (and have to use pnTables).
NOTE You cannot specify an object *and* and where clause together, one must be blank. To use a where clause you should use pnTables and make object an empty array.
// using an object to build the where clause
DBUtil::deleteObject ($obj, 'customers');
// building a where clause
$pntables = pnDBGetTables();
$column = $pntables['customers_column'];
$where = "WHERE $column[name]='Fred' AND $column[country]='Netherlands'";
DBUtil::deleteObject (array(), 'customers', $where);
DBUtil::deleteObject ($obj, 'customers');
// building a where clause
$pntables = pnDBGetTables();
$column = $pntables['customers_column'];
$where = "WHERE $column[name]='Fred' AND $column[country]='Netherlands'";
DBUtil::deleteObject (array(), 'customers', $where);
deleteWhere
/**
* Delete (an) object(s) via a where clause
*
* @param tablename The tablename key for the PNTables structure
* @param where The where-clause to use
*
* @return The result from the delete operation
*/
function deleteWhere ($tablename, $where)
* Delete (an) object(s) via a where clause
*
* @param tablename The tablename key for the PNTables structure
* @param where The where-clause to use
*
* @return The result from the delete operation
*/
function deleteWhere ($tablename, $where)
deleteWhere ($tablename, $where)
This function allows us to create a custom where clause. Remember to use pnTables to get the correct column names:
$pntables = pnDBGetTables();
$column = $pntables['customers_column'];
$where = "WHERE $column[name]='Fred' AND $column[country]='Netherlands'";
DBUtil::deleteWhere ('customers', $where);
$column = $pntables['customers_column'];
$where = "WHERE $column[name]='Fred' AND $column[country]='Netherlands'";
DBUtil::deleteWhere ('customers', $where);
If the $where clause blank it will effectively empty the table.
Previous | Top | Next
CategoryDeveloperDocs
