Skip to content

Commit 6ab9dc4

Browse files
authored
Merge pull request #1 from enrybisco/enrybisco-patch-1-NullInsertion
Update MysqliDb.php
2 parents 16564ba + fd16866 commit 6ab9dc4

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

MysqliDb.php

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -543,22 +543,6 @@ private function queryUnprepared($query)
543543
throw new Exception(sprintf('Unprepared Query Failed, ERRNO: %u (%s)', $this->mysqli()->errno, $this->mysqli()->error), $this->mysqli()->errno);
544544
}
545545

546-
/**
547-
* Prefix add raw SQL query.
548-
*
549-
* @author Emre Emir <https://github.com/bejutassle>
550-
* @param string $query User-provided query to execute.
551-
* @return string Contains the returned rows from the query.
552-
*/
553-
public function rawAddPrefix($query){
554-
$query = str_replace(PHP_EOL, null, $query);
555-
$query = preg_replace('/\s+/', ' ', $query);
556-
preg_match_all("/(from|into|update|join) [\\'\\´]?([a-zA-Z0-9_-]+)[\\'\\´]?/i", $query, $matches);
557-
list($from_table, $from, $table) = $matches;
558-
559-
return str_replace($table[0], self::$prefix.$table[0], $query);
560-
}
561-
562546
/**
563547
* Execute raw SQL query.
564548
*
@@ -570,15 +554,24 @@ public function rawAddPrefix($query){
570554
*/
571555
public function rawQuery($query, $bindParams = null)
572556
{
573-
$query = $this->rawAddPrefix($query);
574557
$params = array(''); // Create the empty 0 index
575558
$this->_query = $query;
576559
$stmt = $this->_prepareQuery();
577560

578561
if (is_array($bindParams) === true) {
579562
foreach ($bindParams as $prop => $val) {
580-
$params[0] .= $this->_determineType($val);
581-
array_push($params, $bindParams[$prop]);
563+
//HENRY MOD 01
564+
if ($val === null || $val == 'null' || $val == 'NULL' || is_null($val) ) {
565+
$val = 'NULL';
566+
}
567+
$params[0] .= $this->_determineType($val);
568+
569+
if ($val === null || $val == 'null' || $val == 'NULL' || is_null($val) ) {
570+
array_push($params, NULL);
571+
}else{
572+
array_push($params, $bindParams[$prop]);
573+
}
574+
//END: HENRY MOD 01
582575
}
583576

584577
call_user_func_array(array($stmt, 'bind_param'), $this->refValues($params));
@@ -588,7 +581,7 @@ public function rawQuery($query, $bindParams = null)
588581
$this->count = $stmt->affected_rows;
589582
$this->_stmtError = $stmt->error;
590583
$this->_stmtErrno = $stmt->errno;
591-
$this->_lastQuery = $this->replacePlaceHolders($this->_query, $params);
584+
$this->_lastQuery = $this->replacePlaceHolders($this->_query, $params);
592585
$res = $this->_dynamicBindResults($stmt);
593586
$this->reset();
594587

@@ -674,7 +667,9 @@ public function query($query, $numRows = null)
674667
*
675668
* @uses $MySqliDb->setQueryOption('name');
676669
*
677-
* @param string|array $options The options name of the query.
670+
* @param string|array $options The options name of the query.'ALL', 'DISTINCT', 'DISTINCTROW', 'HIGH_PRIORITY', 'STRAIGHT_JOIN', 'SQL_SMALL_RESULT',
671+
'SQL_BIG_RESULT', 'SQL_BUFFER_RESULT', 'SQL_CACHE', 'SQL_NO_CACHE', 'SQL_CALC_FOUND_ROWS',
672+
'LOW_PRIORITY', 'IGNORE', 'QUICK', 'MYSQLI_NESTJOIN', 'FOR UPDATE', 'LOCK IN SHARE MODE'
678673
*
679674
* @throws Exception
680675
* @return MysqliDb
@@ -1453,11 +1448,12 @@ public function ping()
14531448
protected function _determineType($item)
14541449
{
14551450
switch (gettype($item)) {
1456-
case 'NULL':
1451+
14571452
case 'string':
14581453
return 's';
14591454
break;
1460-
1455+
//HENRY MOD 02
1456+
case 'NULL':
14611457
case 'boolean':
14621458
case 'integer':
14631459
return 'i';
@@ -2057,10 +2053,13 @@ protected function replacePlaceHolders($str, $vals)
20572053
if (is_object($val)) {
20582054
$val = '[object]';
20592055
}
2060-
if ($val === null) {
2061-
$val = 'NULL';
2062-
}
2063-
$newStr .= substr($str, 0, $pos) . "'" . $val . "'";
2056+
if ($val === null || $val == 'null' || $val == 'NULL' || is_null($val) ) {
2057+
$val = "NULL";
2058+
$newStr .= substr($str, 0, $pos) . $val ;
2059+
}else{
2060+
$newStr .= substr($str, 0, $pos) . "'" . $val . "'";
2061+
}
2062+
20642063
$str = substr($str, $pos + 1);
20652064
}
20662065
$newStr .= $str;

0 commit comments

Comments
 (0)