php - Mysqli not showing errors properly -
i trying learn mysqli of functions. 1 thing left have proper error reporting across layers. don't understand why following snippet of code detects error won't error number nor error code.
function get_pid_tid_by_pk($con,$ourid) { $returned['errno'] =""; $returned['error'] =""; //mistake on here!!! if(!$stmt = $con->prepare("elect gene_name,jgi_protein_id,jgi_transcript_id jgi_transid_protid_match our_protein_id = ?")) { $returned['errno'] = $con->errno; $returned['error'] = $con->error; return $returned; } if(!$stmt->bind_param('s',$ourid)) { $returned['errno'] = $stmt->errno; $returned['error'] = $stmt->error; return $returned; } if(!$stmt->execute()) { $returned['errno'] = $stmt->errno; $returned['error'] = $stmt->error; return $returned; } $stmt->bind_result($gene_name,$jgi_protein_id,$jgi_transcript_id); $stmt->fetch(); $fetchedarray['gene_name'] = $gene_name; $fetchedarray['jgi_protein_id'] = $jgi_protein_id; $fetchedarray['jgi_transcript_id'] = $jgi_transcript_id; //have use hack since query returns object , not array , don't want make object oriented if don't know talking ignore comment $returned['assoc'] = $fetchedarray; return $returned; }
the mistake obvious , on 6th line wrote elect instead of select program getting inside block errno , error null. doing wrong.this code works fine if don't break on purpose.
are sure if statement correct?
if(!$stmt = $con->prepare("elect gene_name,jgi_protein_id,jgi_transcript_id jgi_transid_protid_match our_protein_id = ?")) { $returned['errno'] = $con->errno; $returned['error'] = $con->error; return $returned; }
should be
if(($stmt = $con->prepare("elect gene_name,jgi_protein_id,jgi_transcript_id jgi_transid_protid_match our_protein_id = ?")) === false) { $returned['errno'] = $con->errno; $returned['error'] = $con->error; return $returned; }
or split assignment
$stmt = $con->prepare("elect gene_name,jgi_protein_id,jgi_transcript_id jgi_transid_protid_match our_protein_id = ?"); if($stmt === false) { $returned['errno'] = $con->errno; $returned['error'] = $con->error; return $returned; }
Comments
Post a Comment