1
我有这样的控制器和模型:笨秀(我的)SQL INSERT警告
class MyModel extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function insert($data_array)
{
$this->db->insert('table', $data_array);
if($this->db->affected_rows() == 1) {
return true;
}
return false;
}
}
class Panel extends CI_Controller
{
public function submitPrimer()
{
// evaluate data
$this->load->library('form_validation');
$this->load->model('MyModel', 'mymodel');
// validate, set_rules....
$data = array(
'column1' => $value1;
// .....
);
if($this->mymodel->insert($data)) {
echo "inserted";
}
}
}
是否有任何形式的这 - $> DB-> show_warnings()在CI。在mysql控制台中有'show warnings'命令,例如,如果你有数据类型:float并且你插入像这样:insert into table(attribute_float)values('')。正确的方法是插入表(attribute_float)值(NULL)。
我也想知道'插入'是否应该去模型。我一直认为只有'select/get'数据会去。
谢谢。是的,第一种解决方案是尽可能准备数据。我认为有一个'规则'说'你永远不能相信用户的输入'。对于show_warnings,我应该使用:mysql_query(“SHOW WARNINGS”); 链接http://stackoverflow.com/questions/47589/can-i-detect-and-handle-mysql-warnings-with-php – broadband