以下查询先前有效但现在出错。
返回的错误是1054 Unknown column '$variable1' in 'field list'
使用Joomla中的代码并使用Joomla数据库连接访问同一服务器上的非Joomla数据库。
public function add_client($variable1, $variable2, $variable3){
$db = $this->getDbo();
$columns = array('field1', 'field2', 'field3', 'field4', 'field5', 'field6');
$values = array($variable1, $variable2, $variable3, '12', '24', '1');
$query = $db->getQuery(true)
->insert($db->quoteName('#__clients'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
$db->setQuery($query);
if($db->execute()){
return "The record was added successfully";
}else{
return "There was an error adding the record";
}
}
答案 0 :(得分:0)
这个问题是由于这些变量在它们成为数字之前就是文本了!
下面的解决方案
public function add_client($variable1, $variable2, $variable3){
$db = $this->getDbo();
$columns = array('field1', 'field2', 'field3', 'field4', 'field5', 'field6');
$values = array($db->quote($variable1), $db->quote($variable2), $db->quote($variable3), '12', '24', '1');
$query = $db->getQuery(true)
->insert($db->quoteName('#__clients'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
$db->setQuery($query);
if($db->execute()){
return "The record was added successfully";
}else{
return "There was an error adding the record";
}
}