Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions example/insert_demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@
// set error log mode true to show error on screen or false to log in log file
$db->setErrorLog(true);

// Example -1
// Example -1
$dataArray = ['first_name' => 'Sid', 'last_name' => 'Mike', 'age' => 45];
// use insert function
$q = $db->insert('test', $dataArray)->showQuery()->getLastInsertId();
PDOHelper::PA($q);


// Example -2
// Example -2
$dataArray = ['first_name' => 'Scott', 'last_name' => 'Dimon', 'age' => 55];
// use insert function
$q = $db->insert('test', $dataArray)->showQuery()->getLastInsertId();
PDOHelper::PA($q);


// Example -3
// Example -3
$dataArray = ['first_name' => 'Simran', 'last_name' => 'Singh', 'age' => 25];
// use insert function
$q = $db->insert('testt', $dataArray)->showQuery()->getLastInsertId();
PDOHelper::PA($q);


// Example -4
// Example -4
// use insert function
$q = $db->insert('test', $dataArray)->showQuery()->getLastInsertId();
// print array last insert id
Expand Down
38 changes: 19 additions & 19 deletions example/select_demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require_once '../src/class.pdowrapper.php';

// database connection setings
$dbConfig = array("host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => '');
$dbConfig = ["host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => ''];
// get instance of PDO Wrapper object
$db = new PdoWrapper($dbConfig);

Expand All @@ -16,50 +16,50 @@
$db->setErrorLog(true);


// Example -1
$selectFields = array('customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone');
// Example -1
$selectFields = ['customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone'];
// set where condition
$whereConditions = array('customerNumber' => 103);
$whereConditions = ['customerNumber' => 103];
// select with where and bind param use select method
$q = $db->select('customers', $selectFields, $whereConditions)->showQuery()->results();
// print array result
PDOHelper::PA($q);

// Example -2
$whereConditions = array('lastname =' => 'bow', 'or jobtitle =' => 'Sales Rep', 'and isactive =' => 1, 'and officecode =' => 1);
$data = $db->select('employees', array('employeenumber', 'lastname', 'jobtitle'), $whereConditions)->showQuery()->results();
// Example -2
$whereConditions = ['lastname =' => 'bow', 'or jobtitle =' => 'Sales Rep', 'and isactive =' => 1, 'and officecode =' => 1];
$data = $db->select('employees', ['employeenumber', 'lastname', 'jobtitle'], $whereConditions)->showQuery()->results();
// print array result
PDOHelper::PA($q);


// Example -3
$whereConditions = array('lastname =' => 'bow', 'or jobtitle =' => 'Sales Rep', 'and isactive =' => 1, 'and officecode =' => 1);
// Example -3
$whereConditions = ['lastname =' => 'bow', 'or jobtitle =' => 'Sales Rep', 'and isactive =' => 1, 'and officecode =' => 1];
// select with where and bind param use select method
$q = $db->select('employees', array('employeeNumber', 'lastName', 'firstName'), $whereConditions)->showQuery()->results();
$q = $db->select('employees', ['employeeNumber', 'lastName', 'firstName'], $whereConditions)->showQuery()->results();
// print array result
PDOHelper::PA($q);


// Example -4
$selectFields = array('customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone');
// Example -4
$selectFields = ['customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone'];
// set where condition
$whereConditions = array('customerNumber' => 103, 'contactLastName' => 'Schmitt');
$array_data = array(
$whereConditions = ['customerNumber' => 103, 'contactLastName' => 'Schmitt'];
$array_data = [
'customerNumber =' => 103,
'and contactLastName =' => 'Schmitt',
'and age =' => 30,
'or contactLastName =' => 'Schmitt',
'and age <' => 45,
'or age >' => 65
);
];
// select with where and bind param use select method
$q = $db->select('customers', $selectFields, $array_data);
// print array result
PDOHelper::PA($q);


// Example -5
$selectFields = array('customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone');
// Example -5
$selectFields = ['customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone'];
// set where condition
$whereConditions = [];
// select with where and bind param use select method
Expand All @@ -68,8 +68,8 @@
PDOHelper::PA($q);


// Example -6
$selectFields = array('customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone');
// Example -6
$selectFields = ['customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone'];
// set where condition
$whereConditions = [];
// select with where and bind param use select method
Expand Down
28 changes: 8 additions & 20 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Dframe\Database;

use \PDO;
use Dframe\Database\PdoWrapper;

class Database extends PdoWrapper
{
Expand All @@ -33,17 +32,17 @@ class Database extends PdoWrapper
* @param array $dsn
* @param array $config
*/
function __construct($dsn = [], $config = null)
public function __construct($dsn = [], $config = null)
{
$this->config = $config;
if (is_null($this->config)) {
$this->config = [
'logDir' => APP_DIR . 'View/logs/',
'attributes' => [
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, // Set pdo error mode silent
//PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // If you want to Show Class exceptions on Screen, Uncomment below code
PDO::ATTR_EMULATE_PREPARES => false, // Use this setting to force PDO to either always emulate prepared statements (if TRUE), or to try to use native prepared statements (if FALSE).
//PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // If you want to Show Class exceptions on Screen, Uncomment below code
PDO::ATTR_EMULATE_PREPARES => false, // Use this setting to force PDO to either always emulate prepared statements (if TRUE), or to try to use native prepared statements (if FALSE).
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC // Set default pdo fetch mode as fetch assoc
]
];
Expand Down Expand Up @@ -178,8 +177,8 @@ public function prepareWhere($whereObject)
$params = [];
if (!empty($whereObject)) {
$arr = [];
/***
** @var $chunk WhereChunk
/***
** @var $chunk WhereChunk
*/
foreach ($whereObject as $chunk) {
list($wSQL, $wParams) = $chunk->build();
Expand All @@ -195,8 +194,6 @@ public function prepareWhere($whereObject)
} else {
$this->_setParams = $params;
}


} else {
$this->_setWhere = null;
//$this->_setParams = [];
Expand All @@ -207,7 +204,6 @@ public function prepareWhere($whereObject)
//

return $this;

}

/**
Expand All @@ -223,9 +219,9 @@ public function prepareHaving($havingObject)
if (!empty($havingObject)) {
$arr = [];
/**
*
*
* @var $chunk WhereChunk
*
* @var $chunk WhereChunk
*/
foreach ($havingObject as $chunk) {
list($wSQL, $wParams) = $chunk->build();
Expand All @@ -242,8 +238,6 @@ public function prepareHaving($havingObject)
} else {
$this->_setParams = $params;
}


} else {
$this->_setHaving = null;
//$this->_setParams = [];
Expand All @@ -254,7 +248,6 @@ public function prepareHaving($havingObject)
//

return $this;

}

/**
Expand All @@ -266,7 +259,6 @@ public function prepareHaving($havingObject)
*/
public function prepareOrder($order = null, $sort = null)
{

if ($order == null or $sort == null) {
$this->_setOrderBy = '';
return $this;
Expand All @@ -289,7 +281,6 @@ public function prepareOrder($order = null, $sort = null)
*/
public function prepareQuery($query, $params = false)
{

if (isset($params) and is_array($params)) {
$this->prepareParms($params);
}
Expand All @@ -301,7 +292,6 @@ public function prepareQuery($query, $params = false)
}

return $this;

}

/**
Expand All @@ -314,7 +304,6 @@ public function prepareGroupBy($groupBy)
{
$this->_setGroupBy = ' GROUP BY ' . $groupBy;
return $this;

}

/**
Expand Down Expand Up @@ -352,5 +341,4 @@ public function prepareParms($params)
array_push($this->_setParams, $params);
}
}

}
6 changes: 3 additions & 3 deletions src/HavingStringChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class HaveStringChunk
*/
public $bindWhere;

function __construct($string, $bindWhere = null)
public function __construct($string, $bindWhere = null)
{
$this->string = $string;
$this->bindWhere = $bindWhere;
}

function build()
public function build()
{
$paramName = str_replace('.', '_', $this->string);
$column = explode(' ', $paramName);
Expand All @@ -57,7 +57,7 @@ function build()
* @param array $array
* @return void
*/
function flatter($array)
public function flatter($array)
{
$result = [];
foreach ($array as $item) {
Expand Down
5 changes: 2 additions & 3 deletions src/Helper/PDOHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ public function errorBox($data = [])
$style = "style='color:#333846; border:1px solid #777; padding:2px; background-color: #FFC0CB;'";
die("<div $style >ERROR:" . json_encode($data) . "</div>");
}

}
/**
* Class End
**/
* Class End
**/
Loading