[SOVED] MySql Query Update With White Space Field in Query Builder Codeigniter

[SOVED] MySql Query Update With White Space Field in Query Builder Codeigniter


Okay, I updated the code in /system/database/DB_driver.php by modifying the code in the _update function.

From the initial code as follows:
protected function _update($table, $values)
{
foreach ($values as $key => $val) {
$valstr[] = $key . ' = ' . $val;
}
return 'UPDATE ' . $table . ' SET ' . implode(', ', $valstr)
. $this->_compile_wh('qb_where')
. $this->_compile_order_by()
. ($this->qb_limit ? ' LIMIT ' . $this->qb_limit : '');
}
Becomes
protected function _update($table, $values)
{
foreach ($values as $key => $val) {
$key = str_replace('` `', ' ', $key);
$valstr[] = $key . ' = ' . $val;
}
return 'UPDATE ' . $table . ' SET ' . implode(', ', $valstr)
. $this->_compile_wh('qb_where')
. $this->_compile_order_by()
. ($this->qb_limit ? ' LIMIT ' . $this->qb_limit : '');
}

this method helps me update using a query builder on columns that have whitespaces.
[SOVED] Codeigniter : Insert Mysql With Whitespace Field

[SOVED] Codeigniter : Insert Mysql With Whitespace Field


Okay, I updated the code in /system/database/DB_driver.php by modifying the code in the _insert function.

From the initial code as follows:
protected function _insert ($table, $keys, $values)
{
return 'INSERT INTO'. $table. '('. implode (',', $keys). ') VALUES ('. implode (',', $values). ')';
}

Becomes

protected function _insert ($table, $keys, $values)
{
$keys = str_replace ('` `', ' ', $keys);
return 'INSERT INTO'. $ table. '('. implode (',', $keys). ') VALUES ('. implode (',', $values). ')';
}

this method helps me insert using a query builder on columns that have whitespaces.

Ini Juga Menarik