PHP mySQL numRows() usage and errors? -


i have following code using check constraints on database(for class). u trying number of rows returned query , keep getting same error on line

$count1= $ires1->numrows(mdb2_fetchmode_assoc); 

error:

> call member function numrows() on non-object 

i've been pulling hair out because other functions similar 1 work fine, function doesn't work. there stands out in one?

the argument $db connection database, pno integer , essn text.. i'm not sure doing wrong..

<?php function submitcheck($db){     $essn= $_post['essn'];     $pno=$_post['pno'];      $query1 = "select * works_on pno=? , essn=?";     $types1 = array('integer','text');     $stmt1 = $db->prepare($query1, $types1, mdb2_prepare_manip);      if (mdb2::iserror($stmt1)) {         print("bad prepared statement:" . $stmt->getmessage());     }      $queryargs1 = array($pno, $essn);     $ires1 = $stmt1->execute($queryargs1);     $count1= $ires1->numrows(mdb2_fetchmode_assoc);     //print("the project number entered $count1[pno]");     if(!(count($count1)==0)){         print("the employee part of project! if want update hours, please select update!");         return false;     }     return true; } ?> 

$count1 = $stmt1->rowcount(); 

$ires1 not object, boolean, stated in php pdostatement::rowcount documentation.

a warning though, php.net site:

if last sql statement executed associated pdostatement select statement, databases may return number of rows returned statement. however, behaviour not guaranteed databases , should not relied on portable applications.

there have suggested solution too:

for databases, pdostatement::rowcount() not return number of rows affected select statement. instead, use pdo::query() issue select count(*) statement same predicates intended select statement, use pdostatement::fetchcolumn() retrieve number of rows returned. application can perform correct action."

i did not know , couldn't find information on method numrows, that's far can go. luck!


Comments