CodeIgniter phpMyAdmin - 插入到名称中带有空格的表中

时间:2014-03-09 17:17:36

标签: php mysql sql codeigniter

$this->db->insert('Table One',$data);

这会出错。并显示等效的sql,插入。

INSERT INTO `Table` One (`col1`, `col2`) VALUES ('----', '------')

有没有办法插入?

也许使用通配符?或任何特殊字符替换phpmyadmin的空间到udnerstand?还是phpmyadmin的错?

3 个答案:

答案 0 :(得分:0)

如果表名中有空格,则需要引用全名:

INSERT INTO `Table One` (`col1`, `col2`) VALUES ('----', '------')

答案 1 :(得分:0)

不幸的是,似乎活动记录库不支持带空格的表名。我查看了核心文件,insert()函数调用了表名和系统中的protect_identifiers函数/database/DB_driver.php有以下代码

// If the item has an alias declaration we remove it and set it aside.
// Basically we remove everything to the right of the first space
$alias = '';
if (strpos($item, ' ') !== FALSE)
{
    $alias = strstr($item, " ");
    $item = substr($item, 0, - strlen($alias));
}

所以删除第一个空格后的所有内容。所以看起来你唯一的选择是进行像

这样的查询
$this->db->query('INSERT INTO `Table One` ...');

或删除表名中的空格

对不起。希望有所帮助

答案 2 :(得分:0)

我在进行更新通话时发现了类似的问题

$this->myBaseTable = "my table";
$this->db->update($this->myBaseTable); //errors

如果您将滴答声添加到表格声明中,那么似乎工作正常,即

$this->myBaseTable = "`my table`";
相关问题