I'm trying to dynamically create tables in MySQL
, using CodeIgniter
PHP framework:
if($colname != ''){
$str = "CREATE TABLE IF NOT EXISTS $colname (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), site_id INT NOT NULL, name BLOB NOT NULL)ENGINE=INNOBD;";
$query = $this->db->query($str);
When I execute that from the MySQL
command prompt, it created the table perfectly. However, if it's done through CodeIgniter
, I'm getting the following error:
<body>
<div id="container">
<h1>A Database Error Occurred</h1>
<p>Error Number: 1064</p><p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tc 11' (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), site_id INT NOT NULL, ' at line 1</p><p>CREATE TABLE IF NOT EXISTS 'tc 11' (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), site_id INT NOT NULL, name BLOB NOT NULL)ENGINE=INNOBD;</p>
What's going on here? Thanks