Welcome Guest, Not a member yet? Register   Sign In
I will get Error Number: 1064 if I use reserved words in table
#1

[eluser]Unknown[/eluser]
if I use active record to run select, insert, update, delete or truncate query and my table name or its rows' name contains reserved words the mysql driver will tell me: "
A Database Error Occurred
Error Number: 1064

INSERT INTO ci173_1064_test (name, show, default, order, limit, group) VALUES ('CI pages -> 1064 test', 1, 'default', 'ascendant', 888, 3)
"

There is the code in _insert() which causes the error:
/system/database/drivers/mysql/mysql_driver.php::535
Code:
function _insert($table, $keys, $values)
{    
    return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
should be:
Code:
function _insert($table, $keys, $values)
{    
    return "INSERT INTO `".$table."` (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")";
}
Should mend the other statements same way.

I used this table structure:
Code:
CREATE TABLE `ci173_1064_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`show` tinyint(1) NOT NULL,
`default` varchar(255) NOT NULL,
`order` varchar(255) NOT NULL,
`limit` int(11) NOT NULL,
`group` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

and I use CI 1.7.3
#2

[eluser]CroNiX[/eluser]
Or better yet, don't use reserved words. If you REALLY need to (should never the case), manually put the `` tickmarks around them in your query.

$this->db->select('`order`')->order_by('`order`')->get('sometable')->result_array();




Theme © iAndrew 2016 - Forum software by © MyBB