php - MySQLI Prepared Statement: num_rows & fetch_assoc -


below poorly written , heavily misunderstood php code no error checking. honest, i'm struggling little getting head around maze of php->mysqli functions! please provide example of how 1 use prepared statements collect results in associative array whilst getting row count $stmt? code below i'm playing around with. think bit that's throwing me off using $stmt values after store_result , trying collect assoc array, , i'm not sure why...

$mysqli = mysqli_connect($config['host'], $config['user'], $config['pass'], $config['db']); $stmt = $mysqli->prepare("select * licences generated = ?"); $stmt->bind_param('i', $core['id']); $result = $stmt->execute(); $stmt->store_result();  if ($stmt->num_rows >= "1") {      while($data = $result->fetch_assoc()){          //loop through results here $data[]      }  }else{      echo "0 records found";  } 

i feel little cheeky asking code, working demonstration of circumstances feel need understand what's going on. million!

true, databasefunctions bit weird. you'll there.

the code looks bit iffy, heres how works:

a connection build, statement prepared, parameter bound , it's executed, well.

$result = $stmt->execute(); //execute() tries fetch result set. returns true on succes, false on failure. $stmt->store_result(); //store_result() "binds" last given answer statement-object for... reasons. can use it!  if ($stmt->num_rows >= "1") { //uses stored result , counts rows.    while($data = $result->fetch_assoc()){          //and here, answer-object turned array-(object)         // can worked nicely.         //it loops trough entries in array.   }  }else{     echo "0 records found"; } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -