Cart Boxx – Database Library Reference

THE CLASS ITSELF

class DB

Description: Database related functions, uses PDO.
NOTE!: Make sure the you have set the credentials correctly in cart-boxx/core/config.php
File: cart-boxx/core/lib/LIB_DB.php

Example Usage
$_CB->extend(“DB”);
$_CB->DB->connect();

 

THE FUNCTIONS

function connect

Description: Connect to the database, this is done “automatically” in cart-boxx/index.php when the engine fires up.

Parameters
DB_HOST, DB_CHARSET, DB_NAME, DB_USER, DB_PASSWORD must be set
Return
[BOOL] True on success, will HALT the system on failure.
function select

Description: The plain Jane select query with a small twist.

Parameters
[STRING] $sql – The select SQL to run
[ARRAY] $cond – The WHERE conditions
[STRING] $key – Optional, will sort the results with this field as the key
[STRING] $value – Optional, if both $key and $value are provided, the results will be sorted [$key=>$value, $key=>$value, etc…]
Return
[ARRAY] Search result
[BOOL] False on SQL error
Example Usage
$_CB->extend(“DB”);
$_CB->DB->select(“SELECT * FROM `users` WHERE `user_id` IN (?,?)”, [88,99],”user_id”,”user_name”);
function query

Description: Good old insert/update/delete SQL query.

Parameters
[STRING] $sql – The query string
[ARRAY] $data – Data to insert/update/delete
Return
[BOOL] True on success, false on fail
Example Usage
$_CB->extend(“DB”);
$_CB->DB->query(“INSERT INTO `users` (`name`, `email`) VALUES (?,?)”, [‘John’,’john@doe.com’]);
function start & end

Description: Auto commit off. Start and end are used in a pair, along with query.

Parameters
[BOOL] $commit – Pass in a true or false into function end to commit or rollback.
Return
None
Example Usage
$_CB->DB->start();
$pass = $_CB->DB->query(“INSERT INTO `users` (`name`, `email`) VALUES (?,?)”, [‘John’,’john@doe.com’]);
if ($pass) { $pass = $_CB->DB->query(“INSERT INTO `address_book` (`name`, `email`) VALUES (?,?)”, [‘John’,’john@doe.com’]); )
$_CB->DB->end($pass);

Leave a Comment

Your email address will not be published. Required fields are marked *