我在实现以下方法时遇到问题:
private function query($statement, $params = array(), $name = ""){
try{
$this->prepare($statement, $name);
}catch (Exception $e){
echo 'Exception: ', $e->getMessage(), "\n";
}
try{
return $this->execute($name, $params);
}catch (Exception $e){
echo 'Exception: ', $e->getMessage(), "\n";
}
}
第二个try-block应该从另一个调用的方法返回值。我这样称呼它:
$resultset = $db->select('SELECT * FROM tabelle WHERE "ID" > $1', array(1));
var_dump($resultset);
并获得NULL。
如果我在try-block中使用var_dump值,我得到一个结果:
private function query($statement, $params = array(), $name = ""){
try{
$this->prepare($statement, $name);
}catch (Exception $e){
echo 'Exception: ', $e->getMessage(), "\n";
}
try{
var_dump($this->execute($name, $params));
}catch (Exception $e){
echo 'Exception: ', $e->getMessage(), "\n";
}
}
array(3){[" ID"] =>字符串(1)" 2" ["名称"] => string(13)" name1" ["时间"] => string(26)" 2012-09-11 20:23:38.854918" } NULL
我做错了什么?
编辑 $ db->选择和发布方法之间的部分:
public function select($statement, $params = array(), $name){
$this->setQueryType("select"); // just a setter
return $this->query($statement, $params, $name);
}
答案 0 :(得分:0)
尝试存储来自execute的返回值并在方法结束时返回它并查看它是否有效?
private function query($statement, $params = array(), $name = ""){
$return = false;
try{
$this->prepare($statement, $name);
$return = $this->execute($name, $params);
}
catch (Exception $e){
echo 'Exception: ', $e->getMessage(), "\n";
}
return $return;
}