diff --git a/example/insert_demo.php b/example/insert_demo.php
index e1c7ba2..863c2ed 100644
--- a/example/insert_demo.php
+++ b/example/insert_demo.php
@@ -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
diff --git a/example/select_demo.php b/example/select_demo.php
index 61980b4..f8ab9f0 100644
--- a/example/select_demo.php
+++ b/example/select_demo.php
@@ -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);
@@ -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
@@ -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
diff --git a/src/Database.php b/src/Database.php
index 65934e1..9a16b3f 100644
--- a/src/Database.php
+++ b/src/Database.php
@@ -10,7 +10,6 @@
namespace Dframe\Database;
use \PDO;
-use Dframe\Database\PdoWrapper;
class Database extends PdoWrapper
{
@@ -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
]
];
@@ -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();
@@ -195,8 +194,6 @@ public function prepareWhere($whereObject)
} else {
$this->_setParams = $params;
}
-
-
} else {
$this->_setWhere = null;
//$this->_setParams = [];
@@ -207,7 +204,6 @@ public function prepareWhere($whereObject)
//
return $this;
-
}
/**
@@ -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();
@@ -242,8 +238,6 @@ public function prepareHaving($havingObject)
} else {
$this->_setParams = $params;
}
-
-
} else {
$this->_setHaving = null;
//$this->_setParams = [];
@@ -254,7 +248,6 @@ public function prepareHaving($havingObject)
//
return $this;
-
}
/**
@@ -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;
@@ -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);
}
@@ -301,7 +292,6 @@ public function prepareQuery($query, $params = false)
}
return $this;
-
}
/**
@@ -314,7 +304,6 @@ public function prepareGroupBy($groupBy)
{
$this->_setGroupBy = ' GROUP BY ' . $groupBy;
return $this;
-
}
/**
@@ -352,5 +341,4 @@ public function prepareParms($params)
array_push($this->_setParams, $params);
}
}
-
}
diff --git a/src/HavingStringChunk.php b/src/HavingStringChunk.php
index b273022..c819618 100644
--- a/src/HavingStringChunk.php
+++ b/src/HavingStringChunk.php
@@ -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);
@@ -57,7 +57,7 @@ function build()
* @param array $array
* @return void
*/
- function flatter($array)
+ public function flatter($array)
{
$result = [];
foreach ($array as $item) {
diff --git a/src/Helper/PDOHelper.php b/src/Helper/PDOHelper.php
index 9139551..71dd0c7 100644
--- a/src/Helper/PDOHelper.php
+++ b/src/Helper/PDOHelper.php
@@ -201,8 +201,7 @@ public function errorBox($data = [])
$style = "style='color:#333846; border:1px solid #777; padding:2px; background-color: #FFC0CB;'";
die("
ERROR:" . json_encode($data) . "
");
}
-
}
/**
- * Class End
- **/
\ No newline at end of file
+ * Class End
+ **/
diff --git a/src/PdoWrapper.php b/src/PdoWrapper.php
index f4e3433..07e2f06 100644
--- a/src/PdoWrapper.php
+++ b/src/PdoWrapper.php
@@ -27,7 +27,7 @@
*/
/**
- * Class Start
+ * Class Start
*
* @author Neeraj Singh
* @author Sławomir Kaleta
@@ -159,7 +159,7 @@ class PdoWrapper extends \PDO
*
* @var array
*/
- private $_aValidOperation = array('SELECT', 'INSERT', 'UPDATE', 'DELETE');
+ private $_aValidOperation = ['SELECT', 'INSERT', 'UPDATE', 'DELETE'];
/**
* PDO Object
@@ -185,18 +185,15 @@ public function __construct($dsn = [], $settings = ['attributes' => []])
}
$this->_db_info = $dsn;
} else {
-
if (count($this->_db_info) > 0) {
$dsn = $this->_db_info;
// check valid array key name
if (!isset($dsn['host']) || !isset($dsn['dbname']) || !isset($dsn['username']) || !isset($dsn['password'])) {
die("Dude!! You haven't set valid db config array key.");
}
-
} else {
die("Dude!! You haven't set valid db config array.");
}
-
}
if (!isset($dsn['dbtype'])) {
@@ -217,13 +214,10 @@ public function __construct($dsn = [], $settings = ['attributes' => []])
$password,
$settings['attributes']
);
-
-
} catch (PDOException $e) {
// get pdo error and pass on error method
die("ERROR in establish connection: " . $e->getMessage());
}
-
}
/**
@@ -248,7 +242,7 @@ public static function getPDO($dsn = [])
*/
public function start()
{
- // begin the transaction
+ // begin the transaction
$this->beginTransaction();
}
@@ -266,7 +260,7 @@ public function end()
*/
public function back()
{
- // roll back the transaction if we fail
+ // roll back the transaction if we fail
$this->rollback();
}
@@ -370,12 +364,10 @@ public function pdoQuery($sSql = '', $aBindWhereParam = [])
} else {
self::error($this->_oSTH->errorInfo()); // if not run pdo statement sed error
}
-
} catch (PDOException $e) {
self::error($e->getMessage() . ': ' . __LINE__);
} // end try catch block
-
- } elseif (count($aBindWhereParam) > 0) { // if query pass with bind param
+ } elseif (count($aBindWhereParam) > 0) { // if query pass with bind param
$this->aData = $aBindWhereParam;
// start binding fields
@@ -390,46 +382,41 @@ public function pdoQuery($sSql = '', $aBindWhereParam = [])
case 'SELECT':
// get affected rows by select statement
$this->iAffectedRows = $this->_oSTH->rowCount();
- // get pdo result array
- $this->aResults = $this->_oSTH->fetchAll();
- // return PDO instance
- return $this;
- break;
+ // get pdo result array
+ $this->aResults = $this->_oSTH->fetchAll();
+ // return PDO instance
+ return $this;
+ break;
case 'INSERT':
// return last insert id
$this->iLastId = $this->lastInsertId();
- // return PDO instance
- return $this;
- break;
+ // return PDO instance
+ return $this;
+ break;
case 'UPDATE':
// get affected rows
$this->iAffectedRows = $this->_oSTH->rowCount();
- // return PDO instance
- return $this;
- break;
+ // return PDO instance
+ return $this;
+ break;
case 'DELETE':
// get affected rows
$this->iAffectedRows = $this->_oSTH->rowCount();
- // return PDO instance
- return $this;
- break;
+ // return PDO instance
+ return $this;
+ break;
endswitch;
// close pdo cursor
$this->_oSTH->closeCursor();
-
} else {
self::error($this->_oSTH->errorInfo());
}
-
-
} catch (PDOException $e) {
self::error($e->getMessage() . ': ' . __LINE__);
} // end try catch block to get pdo error
-
} else {
self::error('Error Query');
}
-
}
/**
@@ -471,7 +458,6 @@ public function select($sTable = '', $aColumn = [], $aWhere = [], $sOther = '')
unset($tmp);
// set class sql property
$this->sSql = "SELECT $sField FROM `$sTable` WHERE $sWhere $sOther;";
-
} else {
$this->sSql = "SELECT $sField FROM `$sTable` $sOther;"; // if no where condition pass by user
}
@@ -496,20 +482,16 @@ public function select($sTable = '', $aColumn = [], $aWhere = [], $sOther = '')
$this->_oSTH->closeCursor();
// return self object
return $this;
-
} else {
self::error($this->_oSTH->errorInfo()); // catch pdo error
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
} // end try catch block to get pdo error
-
- } else { // if table name empty
+ } else { // if table name empty
self::error('Table name not found..');
}
-
}
/**
@@ -557,7 +539,6 @@ public function insert($sTable, $aData = [])
} else {
self::error($this->_oSTH->errorInfo());
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
@@ -565,11 +546,9 @@ public function insert($sTable, $aData = [])
} else {
self::error('Data not in valid format..');
}
-
} else {
self::error('Table name not found..');
}
-
}
/**
@@ -620,7 +599,6 @@ public function insertBatch($sTable, $aData = [], $safeModeInsert = true)
} else {
self::error($this->_oSTH->errorInfo());
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
@@ -672,15 +650,12 @@ public function insertBatch($sTable, $aData = [], $safeModeInsert = true)
$this->_oSTH->closeCursor();
// return this object
return $this;
-
} else {
self::error('Data not in valid format..');
}
-
} else {
self::error('Table name not found..');
}
-
}
/**
@@ -718,7 +693,7 @@ public function update($sTable = '', $aData = [], $aWhere = [], $sOther = '')
$sWhere = implode(' AND ', $tmp);
// unset temp array
unset($tmp);
- // make sql query to update
+ // make sql query to update
$this->sSql = "UPDATE `$sTable` SET $sFields WHERE $sWhere $sOther;";
// on PDO prepare statement
$this->_oSTH = $this->prepare($this->sSql);
@@ -736,24 +711,19 @@ public function update($sTable = '', $aData = [], $aWhere = [], $sOther = '')
$this->_oSTH->closeCursor();
// return self object
return $this;
-
} else {
self::error($this->_oSTH->errorInfo());
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
} // try catch block end
-
} else {
self::error('update statement not in valid format..');
}
-
} else {
self::error('Table name not found..');
}
-
}
/**
@@ -786,7 +756,7 @@ public function delete($sTable, $aWhere = [], $sOther = '')
$this->_bindPdoNameSpace($aWhere);
// set array data
$this->aData = $aWhere;
- // Use try Catch
+ // Use try Catch
try {
if ($this->_oSTH->execute()) {
@@ -796,24 +766,19 @@ public function delete($sTable, $aWhere = [], $sOther = '')
$this->_oSTH->closeCursor();
// return this object
return $this;
-
} else {
self::error($this->_oSTH->errorInfo());
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
} // end try catch here
-
} else {
self::error('Not a valid where condition..');
}
-
} else {
self::error('Table name not found..');
}
-
}
/**
@@ -824,7 +789,6 @@ public function delete($sTable, $aWhere = [], $sOther = '')
*/
public function results($type = 'array')
{
-
switch ($type) {
case 'array':
// return array data
@@ -857,7 +821,6 @@ public function count($sTable = '', $sWhere = '')
{
// if table name not pass
if (!empty($sTable)) {
-
if (empty($sWhere)) {
$this->sSql = "SELECT COUNT(*) AS NUMROWS FROM `$sTable`;"; // create count query
} else {
@@ -868,7 +831,6 @@ public function count($sTable = '', $sWhere = '')
// pdo prepare statement
$this->_oSTH = $this->prepare($this->sSql);
try {
-
if ($this->_oSTH->execute()) {
// fetch array result
$this->aResults = $this->_oSTH->fetch();
@@ -879,7 +841,6 @@ public function count($sTable = '', $sWhere = '')
} else {
self::error($this->_oSTH->errorInfo());
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
@@ -887,7 +848,6 @@ public function count($sTable = '', $sWhere = '')
} else {
self::error('Table name not found..');
}
-
}
/**
@@ -910,11 +870,9 @@ public function truncate($sTable = '')
$this->_oSTH->closeCursor();
// return number of count
return true;
-
} else {
self::error($this->_oSTH->errorInfo());
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
@@ -922,7 +880,6 @@ public function truncate($sTable = '')
} else {
self::error('Table name not found..');
}
-
}
/**
@@ -948,7 +905,6 @@ public function drop($sTable = '')
} else {
self::error($this->_oSTH->errorInfo());
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
@@ -956,7 +912,6 @@ public function drop($sTable = '')
}
self::error('Table name not found..');
-
}
/**
@@ -990,7 +945,6 @@ public function customWhere($array_data = [])
foreach ($array_data as $key => $value) {
$key = trim($key);
if (strstr($key, ' ')) {
-
$array = explode(' ', $key);
if (count($array) == '2') {
$random = '';//"_".rand(1,100);
@@ -998,7 +952,6 @@ public function customWhere($array_data = [])
$operator = $array[1];
$tmp[] = "$field $operator :s_$field" . "$random";
$syntax .= " $field $operator :s_$field" . "$random ";
-
} elseif (count($array) == '3') {
$random = '';//"_".rand(1,100);
$condition = $array[0];
@@ -1006,15 +959,14 @@ public function customWhere($array_data = [])
$operator = $array[2];
$tmp[] = "$condition $field $operator :s_$field" . "$random";
$syntax .= " $condition $field $operator :s_$field" . "$random ";
-
}
}
}
- return array(
+ return [
'where' => $syntax,
'bind' => implode(' ', $tmp)
- );
+ ];
}
/**
@@ -1024,7 +976,6 @@ public function customWhere($array_data = [])
*/
private function _bindPdoNameSpace($array = [])
{
-
if (strstr(key($array), ' ')) {
// bind array data in pdo
foreach ($array as $f => $v) {
@@ -1035,18 +986,17 @@ private function _bindPdoNameSpace($array = [])
// is string found then pdo param as string
case 'string':
$this->_oSTH->bindParam(":s" . "_" . "$field", $array[$f], PDO::PARAM_STR);
- break;
- // if int found then pdo param set as int
+ break;
+ // if int found then pdo param set as int
case 'integer':
$this->_oSTH->bindParam(":s" . "_" . "$field", $array[$f], PDO::PARAM_INT);
- break;
- // if boolean found then set pdo param as boolean
+ break;
+ // if boolean found then set pdo param as boolean
case 'boolean':
$this->_oSTH->bindParam(":s" . "_" . "$field", $array[$f], PDO::PARAM_BOOL);
- break;
+ break;
endswitch;
} // end for each here
-
} else {
// bind array data in pdo
@@ -1056,15 +1006,15 @@ private function _bindPdoNameSpace($array = [])
// is string found then pdo param as string
case 'string':
$this->_oSTH->bindParam(":s" . "_" . "$f", $array[$f], PDO::PARAM_STR);
- break;
- // if int found then pdo param set as int
+ break;
+ // if int found then pdo param set as int
case 'integer':
$this->_oSTH->bindParam(":s" . "_" . "$f", $array[$f], PDO::PARAM_INT);
- break;
- // if boolean found then set pdo param as boolean
+ break;
+ // if boolean found then set pdo param as boolean
case 'boolean':
$this->_oSTH->bindParam(":s" . "_" . "$f", $array[$f], PDO::PARAM_BOOL);
- break;
+ break;
endswitch;
} // end for each here
}
@@ -1084,15 +1034,15 @@ private function _bindPdoParam($array = [])
// is string found then pdo param as string
case 'string':
$this->_oSTH->bindParam($f + 1, $array[$f], PDO::PARAM_STR);
- break;
- // if int found then pdo param set as int
+ break;
+ // if int found then pdo param set as int
case 'integer':
$this->_oSTH->bindParam($f + 1, $array[$f], PDO::PARAM_INT);
- break;
- // if boolean found then set pdo param as boolean
+ break;
+ // if boolean found then set pdo param as boolean
case 'boolean':
$this->_oSTH->bindParam($f + 1, $array[$f], PDO::PARAM_BOOL);
- break;
+ break;
endswitch;
} // end for each here
}
@@ -1113,7 +1063,6 @@ public function error($msg)
// die code
$this->helper()->errorBox($msg);
}
-
}
/**
@@ -1146,7 +1095,6 @@ protected function interpolateQuery()
$sql = $this->_oSTH->queryString;
// handle insert batch data
if (!$this->batch) {
-
$params = ((is_array($this->aData)) && (count($this->aData) > 0)) ? $this->aData : $this->sSql;
if (is_array($params)) {
// build a regular expression for each parameter
@@ -1189,9 +1137,7 @@ protected function interpolateQuery()
}
return $params;
-
} else {
-
$params_batch = ((is_array($this->aData)) && (count($this->aData) > 0)) ? $this->aData : $this->sSql;
$batch_query = '';
@@ -1221,7 +1167,6 @@ protected function interpolateQuery()
}
return $params_batch;
-
}
}
@@ -1278,7 +1223,7 @@ public function execute($aBindWhereParam = [])
{
// clean query from white space
- $sSql = trim($this->_oSTH->queryString);
+ $sSql = trim($this->_oSTH->queryString);
// get operation type
$operation = explode(' ', $sSql);
// make first word in uppercase
@@ -1326,7 +1271,6 @@ public function execute($aBindWhereParam = [])
} else {
self::error($this->_oSTH->errorInfo());
}
-
} catch (PDOException $e) {
// get pdo error and pass on error method
self::error($e->getMessage() . ': ' . __LINE__);
@@ -1340,5 +1284,4 @@ public function __destruct()
{
self::$oPDO = null;
}
-
}
diff --git a/src/WhereChunk.php b/src/WhereChunk.php
index 5b70ad9..2ff0339 100644
--- a/src/WhereChunk.php
+++ b/src/WhereChunk.php
@@ -28,7 +28,7 @@ class WhereChunk
* @param string $value
* @param string $operator
*/
- function __construct($key, $value, $operator = null)
+ public function __construct($key, $value, $operator = null)
{
$this->key = $key;
$this->value = $value;
@@ -40,7 +40,7 @@ function __construct($key, $value, $operator = null)
*
* @return array
*/
- function build()
+ public function build()
{
$params = [];
if ($this->value !== null) {
@@ -58,11 +58,10 @@ function build()
$sql = "{$this->key} $op ?"; // $sql = "{$this->key} $op {$paramName}";
$params[":{$paramName}"] = $this->value;
}
-
} else {
$sql = $sql = "{$this->key} IS NULL ";
}
return [$sql, $params];
}
-}
\ No newline at end of file
+}
diff --git a/src/WhereStringChunk.php b/src/WhereStringChunk.php
index b422f6b..d96f896 100644
--- a/src/WhereStringChunk.php
+++ b/src/WhereStringChunk.php
@@ -13,7 +13,7 @@
/**
* Klasa wspomagajÄ…ca warunki wyszukiwania
* new WhereStringChunk('`kolumna` LIKE ?', ['test']);
- *
+ *
*/
class WhereStringChunk
@@ -27,7 +27,7 @@ class WhereStringChunk
* @param string $string
* @param array $bindWhere
*/
- function __construct($string, $bindWhere = null)
+ public function __construct($string, $bindWhere = null)
{
$this->string = $string;
$this->bindWhere = $bindWhere;
@@ -38,7 +38,7 @@ function __construct($string, $bindWhere = null)
*
* @return array
*/
- function build()
+ public function build()
{
$paramName = str_replace('.', '_', $this->string);
$column = explode(' ', $paramName);
@@ -58,7 +58,7 @@ function build()
* @param array $array
* @return void
*/
- function flatter($array)
+ public function flatter($array)
{
$result = [];
foreach ($array as $item) {
diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php
index 109632d..417fc02 100644
--- a/tests/ConnectionTest.php
+++ b/tests/ConnectionTest.php
@@ -1,17 +1,11 @@
expectException(\Exception::class);
@@ -19,5 +13,4 @@ public function testEmptyPdoQuery()
$test = $this->getConnection()->pdoQuery();
}
-
}
diff --git a/tests/QueryTest.php b/tests/QueryTest.php
index 7f537f5..dd50604 100644
--- a/tests/QueryTest.php
+++ b/tests/QueryTest.php
@@ -1,12 +1,6 @@
'123-123-123'];
$aWhere = ['id' => 23];
$update = $this->getConnection()->update('users', $dataArray, $aWhere)->affectedRows();
$this->assertTrue(is_numeric($update));
-
}
}
diff --git a/tests/TestSetUp.php b/tests/TestSetUp.php
index b6d9b49..d13d4be 100644
--- a/tests/TestSetUp.php
+++ b/tests/TestSetUp.php
@@ -7,7 +7,6 @@
abstract class TestSetUp extends TestCase
{
-
public function getConnection()
{
try {
@@ -23,19 +22,17 @@ public function getConnection()
'logDir' => APP_DIR . 'View/logs/',
'attributes' => [
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // If you want to Show Class exceptions on Screen, Uncomment below code
- PDO::ATTR_EMULATE_PREPARES => true, // 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 => true, // 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
]
];
$this->db = new Database($dbConfig, $config);
-
} catch (\PDOException $e) {
echo $e->getMessage();
}
return $this->db;
}
-
}