好吧,我糊涂了。我正在尝试对数据库(本地)执行查询,但我不断收到连接重置错误。我一直在通用 DAO 类中使用下面的方法来构建查询字符串并传递给 Zend_Db API。
public function insert($params) {
$loop = false;
$keys = $values = '';
foreach($params as $k => $v){
if($loop == true){
$keys .= ',';
$values .= ',';
}
$keys .= $this->db->quoteIdentifier($k);
$values .= $this->db->quote($v);
$loop = true;
}
$sql = "INSERT INTO " . $this->table_name . " ($keys) VALUES ($values)";
//formatResult returns an array of info regarding the status and any result sets of the query
//I've commented that method call out anyway, so I don't think it's that
try {
$this->db->query($sql);
return $this->formatResult(array(
true,
'New record inserted into: '.$this->table_name
));
}catch(PDOException $e) {
return $this->formatResult($e);
}
}
到目前为止,这一切都很好——自从我们生成新表来记录用户输入以来,错误一直在发生。插入字符串如下所示:
INSERT INTO tablename(`id`,`title`,`summary`,`description`,`keywords`,`type_id`,`categories`) VALUES ('5539','Sample Title','Sample content','
\'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In et pellentesque mauris. Curabitur hendrerit, leo id ultrices pellentesque, est purus mattis ligula, vitae imperdiet neque ligula bibendum sapien. Curabitur aliquet nisi et odio pharetra tincidunt. Phasellus sed iaculis nisl. Fusce commodo mauris et purus vehicula dictum. Nulla feugiat molestie accumsan. Donec fermentum libero in risus tempus elementum aliquam et magna. Fusce vitae sem metus. Aenean commodo pharetra risus, nec pellentesque augue ullamcorper nec. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nullam vel elit libero. Vestibulum in turpis nunc.\'','this,is,a,sample,array',1,'category title')
以下是在组装查询 (var_dump) 之前获取的参数:
array
'id' => string '1' (length=4)
'title' => string 'Sample Title' (length=12)
'summary' => string 'Sample content' (length=14)
'description' => string '<p>'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In et pellentesque mauris. Curabitur hendrerit, leo id ultrices pellentesque, est purus mattis ligula, vitae imperdiet neque ligula bibendum sapien. Curabitur aliquet nisi et odio pharetra tincidunt. Phasellus sed iaculis nisl. Fusce commodo mauris et purus vehicula dictum. Nulla feugiat molestie accumsan. Donec fermentum libero in risus tempus elementum aliquam et magna. Fusce vitae sem metus. Aenean commodo pharetra risus, nec pellentesque augue'... (length=677)
'keywords' => string 'this,is,a,sample,array' (length=22)
'type_id' => int 1
'categories' => string 'category title' (length=43)
下一个停靠点是检查表的限制,因为如果“描述”的长度在 300 左右(它在 310 - 330 之间变化),它似乎会插入。字段限制设置为 VARCHAR(1500) 并且该字段的验证不允许超过 1200 的 HTML 超过 800 的内容。
真正的问题是,如果我使用这个 sql 字符串并通过命令行执行它,它可以正常工作 - 所以我一辈子都无法弄清楚出了什么问题。
我尝试过扩展服务器参数,即 意外连接重置:PHP 或 Apache 问题?
所以,简而言之,我被难住了。有任何想法吗?