我的代码有问题。我创建了一个类来搜索作业ID或任务ID。但我无法在MySQL中检索envelope_id。该值应为TESTTEST
<?php
class Envelope {
private $_db, $_data;
public function __construct($taskidorjobid = null, $taskid = null) {
$this -> _db = DB::getInstance();
//$this -> _sessionName = Config::get('session/session_name');
//$this -> _cookieName = Config::get('remember/cookie_name');
if ($taskidorjobid == null && $taskid == null) {
} elseif ($taskid == null) {
$this -> findtaskid($taskidorjobid);
} else {
$this -> find($taskidorjobid, $taskid);
}
}
public function findtaskid($taskid = null) {
if ($taskid) {
$field = 'id';
$data = $this -> _db -> get('task', array($field, '=', $taskid));
if ($data -> count()) {
$this -> _data = $data -> first();
return true;
}
}
return false;
}
public function find($jobid = null, $taskid = null) {
if ($jobid and $taskid) {
//$field = 'id';
//$data = $this -> _db -> get('task', array($field, '=', $task));
$data = $this -> _db -> query("select * from document where job = " . $jobid . " and taskid = " . $taskid);
if ($data -> count()) {
$this -> _data = $data -> first();
return true;
}
}
return false;
}
public function findenvelopeid($taskid = null, $version = null) {
$sql = "select envelope_id from document where taskid = ?, version = ?, latestflag = ?";
$param = array($taskid, $version, "yes");
$data = $this-> _db->query($sql, $param);
//foreach ($data->results() as $row) {
if ($data -> count()) {
$this -> _data = $data -> first();
$envelope_id = $this -> _data -> envelope_id;
return $envelope_id;
}
return false;
}
}
?>
然后在我的另一组php文件中,我调用了函数findenvelopeid,但它没有返回任何值。我可以回复我的$ tid作为$ taskid。
$envelope = new Envelope();
$envelopeid = $envelope->findenvelopeid($tid,"signed_online");
echo "Envelope ID: ".$envelopeid. "<br>";
我的编码器开发的查询功能是:
public function query($sql,$params=array(), $options=array()){
$this->_error=false;
if($this->_query=$this->_pdo->prepare($sql)){
$x=1;
if(count($params)){
foreach($params as $param){
//if(count($options)>=$x){
//var_dump("DB sql: " . $sql . "<br/> x: " . $x . ", param: " . $param . ", options:" . $options[$x-1]);
// $this->_query->bindValue($x,$param, $options[$x-1]);
//}else{
//var_dump("DB sql: " . $sql . "<br/> x: " . $x . ", param: " . $param);
$this->_query->bindValue($x,$param);
//}
$x++;
}
}
if($this->_query->execute()){
$this->_results=$this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count=$this->_query->rowCount();
}else{
//var_dump("<br /> errorcode " . $this->_pdo->errorCode() . "<br />error info:");
//print_r($this->_pdo->errorInfo());
$this->_error=true;
}
}
return $this;
}
请帮忙!
答案 0 :(得分:0)
Blimey, I should use AND
instead of a ,
in my where clause.