php - Can't prepare a query and no error output -
today have problems script, can't prepare query , script doens't retrun error:
table structure(oops wrong table,corrected):
create table if not exists `razorphyn_support_users` ( `id` bigint(11) unsigned not null auto_increment, `name` varchar(50) not null, `mail` varchar(50) not null, `password` varchar(200) not null, `reg_key` varchar(260) not null, `tmp_password` varchar(31) null, `ip_address` varchar(50) not null, `status` enum('0','1','2','3','4') not null default '3', `holiday` enum('0','1') not null default '0', `assigned_tickets` int(5) unsigned not null default 0, `solved_tickets` bigint(11) unsigned not null default 0, primary key (`id`), unique key(`mail`)) engine=myisam default charset=utf8 auto_increment=55;
unpreparable string:
$query = "select `id` ".$supportusertable." `status`='2' , `holiday`='0' , min(`assigned_tickets`) order `solved_tickets` asc" ;
full code(in reality part of it, $stmt
starterd , working,basically it's connected):
file_put_contents('ok.txt',''); $query = "select `id` ".$supportusertable." `status`='2' , `holiday`='0' , min(`assigned_tickets`) order `solved_tickets` asc" ; $prepared = $stmt->prepare($query); if($prepared){ file_put_contents('ok2.txt',''); if($stmt->execute()){ file_put_contents('ok3.txt',''); $stmt->store_result(); $result = $stmt->bind_result($id); file_put_contents('eafv.txt','id: '.$id); if($stmt->num_rows>0){ $query = "update ".$supportticketstable." set operator_id=? id=? "; if($prepared = $stmt->prepare($query)){ if($stmt->bind_param('ii', $id,$tkid)){ if($stmt->execute()){ echo json_encode(array(0=>'created')); } else echo json_encode(array(0=>mysqli_stmt_error($stmt))); } else echo json_encode(array(0=>mysqli_stmt_error($stmt))); } else echo json_encode(array(0=>mysqli_stmt_error($stmt))); } else echo json_encode(array(0=>'no operator available')); } else echo json_encode(array(0=>mysqli_stmt_error($stmt))); } else echo json_encode(array(0=>$stmt->error));
you can't put min() expressions in clause in sql. can put min() expressions in select-list, having clause, , order clause.
what want is:
i select operator minimum number of open ticket , if there multiple operator same value [then] select 1 less solved tickets
here's solution result:
select `id` razorphyn_support_users `status` = 2 , `holiday` = 0 order `assigned_tickets` asc, `solved_tickets` asc limit 1
re comments:
for limit syntax, see https://stackoverflow.com/a/3325580/20860 or mysql manual says:
for compatibility postgresql, mysql supports limit row_count offset offset syntax.
using string-delimiters if type string or enum. made assumption columns integers (i didn't double-check table definition above), , removed string delimiters because they're not necessary integers.
Comments
Post a Comment