Sunday, 15 January 2012

mysql - check if empty in php prepare statement -



mysql - check if empty in php prepare statement -

in prepared statement can retrieve values returned mysql, unable notify user if mysql not homecoming data.

below code of prepared statement.

$database object of mysqli connection.

$stmt = $database->prepare($qrycallproc); $stmt->bind_param('iss',$userid,$trendtype,$university); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($param1,$param2); while($stmt->fetch) { print_r($param1); } $stmt->free_result(); $stmt->close();

i tried using below code after $stmt->bind_result($param1,$param2) not useful:

if(!$stmt->fetch()) { print_r("there no data"); } elseif (is_null($stmt->fetch())) { print_r("there no data"); }

am missing in code or there other way in can this?

you utilize num_rows first check if query yielded rows:

if($stmt->num_rows > 0) { $stmt->store_result(); $stmt->bind_result($param1,$param2); while($stmt->fetch) { echo $param1; } } else { // sorry no rows found }

php mysql mysqli

No comments:

Post a Comment