ci有什么debug方法吗
想着正操作除了问题半天找不出原因$data['dfsdf'] = 'sdfasdafa';
$data['dfsdf'] = '22';
$data['dfsdf'] = 'sdfas22dafa';
$data['dfsdf'] = 'sdf2a';
$this->db->insert('sdfadsf',$data); 可以写 log 呀,然后分析,一般的 PHP 程序我个人很少使用什么断点调试,基本用不上,输出一个 var_dump 足够了。 我是说数据库操作错误,用$this->db->insert();经常出现莫名错误,但看不出来,有个$this->db->lastquery() 只有成功的才显示 如果有数据库错误,错误信息里有 SQL 错误语句呀! 我也经常被这个数据库类搞得莫名奇妙的,明明我的$data中的某个键的值是空字符,insert('table',$data)后,就是会把那个键搞成一个'0'值弄进数据库。。数据库该字段默认值也是为空的。。
为什么嘞, AR 会进行一些过滤,空值会进行转换吧。 但转得也太莫名其秒了,同样的字段设置,同样的空值,为什么有些就转,就些就不转 呵呵,把你有问题的代码贴上来看看。
$timestamp = time();
$updateArray = array(
'title' => $this->input->post('title'),
'content' => $this->input->post('content'),
'author' => $this->input->post('author'),
'fromsite' => $this->input->post('fromsite'),
'keyword' => $this->input->post('keyword'),
'intro' => $this->input->post('intro'),
'extra' => $this->input->post('extra'),
'contentorder' => intval($this->input->post('contentorder')),
'modifieddate' => $timestamp,
'publishdate' => strtotime($this->input->post('publishdate')),
'adminid' => 1
);
//这个switch是用来改变publish和publishdate值的,对我出现的问题没影响,大伙不用管
switch($this->input->post('publishselect')) {
case '2':
if(empty($updateArray['publishdate'])) $updateArray['publishdate'] = $timestamp;
$updateArray['publish'] = '1';
break;
case '1':
if($updateArray['publishdate'] <= $timestamp && $updateArray['publishdate'] > 0) {
$updateArray['publish'] = '1';
} elseif(empty($updateArray['publishdate'])) {
$updateArray['publishdate'] = $timestamp;
$updateArray['publish'] = '1';
} else {
$updateArray['publish'] = '0';
}
break;
default:
$updateArray['publishdate'] = '0';
$updateArray['publish'] = '0';
}
//print_r($updateArray);
//exit;
$indexId = intval($this->input->post('indexid'));
$this->db->update('content',$updateArray,array('indexid'=>$indexId));
我的代码大概就这样,非常奇怪的是,只有keyword跟intro两个字段会出现为空时,变成0插到数据库,而跟这两字段一样的数据库字段设置的author和fromsite等字段却不会。字段设置都是varchar(255) NOT NULL,没有其它特殊设置。。我就纳闷了。。。
放心,在我print_r的时候,都能保证这两字段仍然是空值,所以肯定是update时出现的问题,同样的insert时也是同样问题。
[ 本帖最后由 artfantasy 于 2008-7-4 01:25 编辑 ]
parent::Controller();
$this->output->enable_profiler(TRUE);
写在控制器的构造函数里就可以了
[ 本帖最后由 dalamar 于 2008-7-8 14:09 编辑 ]
页:
[1]