oracle - Using PHP and oci8 to handle a query -
this past paper question database class i'm stuck with. i'm preparing exam, it's okay give away answer.
consider following schema:
borrow(userid: string, callnum: string, copynum: integer, checkout: date, return: date) here php function has error.
function countcheckedoutbookcopies($callnum){ $sql = "select count(*) bookcount borrow return = null , callnum = '".$callnum."'"; $stid = oci_parse($this->conn, $sql); //assume $this->con correct if($row = oci_fetch_object($stid)){ return $row->bookcount; } else{ return -1; } } there 3 questions.
1.find error , fix it.
2.another error occurs, fix it.
3.despite being fixed, function return -1 time. why this?
i'm familiar procedural php using mysql. tried running code , resulted $stid returning boolean time because don't know part right , part wrong.
here things i've tried
1.changing '".$callnum."' '$callnum' (because how i've done in mysql)
2.changing return = null return = 'null' (but don't think case)
3.maybe there wrong concept of getting count(*) instead of *
edit: thought: feel oci8 , mysql pretty same thing, there reason prefer 1 on another? i'm sure mysql more popular one, school seems prefer using oci8 exam questions
thanks in advance!
despite "find error" , "another error occurs":
1.) "return null",
2.) this->conn supposed this->con,
3.) code missing oci_execute($stid);,
4.) oci_free_statement($stid);.
function countcheckedoutbookcopies($callnum){ $sql = "select count(*) bookcount borrow return null , callnum = '$callnum'"; $stid = oci_parse($this->con, $sql); //assume $this->con correct oci_execute($stid); $ret = -1; if($row = oci_fetch_object($stid)){ $ret = $row->bookcount; } oci_free_statement($stid); return $ret; }
Comments
Post a Comment