i have 2 php file (function.php, dp.php) in dp.php i call update function as follow
include('function.php');
$db = new Database();
$db->connect();
$db->update('classes', array('level'=> '(CASE WHEN level = 1 THEN 2
WHEN level = 2 THEN 3
WHEN level = 3 THEN 4
END)','modifiedTime'=>date("Y-m-d H:i:s")), 'level IN (1,2,3)');
$res = $db->getResult();
print_r($res);
and the update function :
public function update($table,$params=array(),$where){
if($this->tableExists($table)){
$args=array();
foreach($params as $field=>$value){
$args[]=$field.'="'.$value.'"';
}
$sql='UPDATE '.$table.' SET '.implode(',',$args).' WHERE '.$where;
$this->myQuery = $sql; // Pass back the SQL
if($query = $this->myconn->query($sql)){
array_push($this->result,$this->myconn->affected_rows);
return true;
}else{
array_push($this->result,$this->myconn->error);
return false;
}
}else{
return false;
}
}
the result i always get is 0 ,where it should be 2, 3, or 4.
the actual statement the is working when it is executed phpmyadmin is:
update classes set level = (CASE WHEN level = 1 THEN 2
WHEN level = 2 THEN 3
WHEN level = 3 THEN 4
END), modifiedTime = date("Y-m-d H:i:s")) WHERE level IN (1,2,3));
thanks in advance
Aucun commentaire:
Enregistrer un commentaire