MYSQL Prepared Statements Select Row_Count -


i have simple sql query:

$stmt = $db_main->prepare("select id user username=? , mail=? limit 1"); $stmt->bind_param('ss', $username, $mail); $stmt->execute(); 

and want know, if found user. want count rows found. tried use rowcount (not safe select) or num_rows or looking if result id numeric (which '' not be, hoped...)

there has easy way count selected row, hasn't be?

check number of rows returned with:

$stmt->num_rows; 

check instance this site.

p.s.: added per question in comment: use fetch() in order next record.

... $stmt->execute(); $stmt->bind_result($user_id); // access id $stmt->store_result();        // optional: buffering (see below)  if ($data = $stmt->fetch()) {     {         print("id: " . $user_id);       } while ($data = $stmt->fetch());  } else {     echo 'no records found.'; } 

regarding store_result() documentation: "you must call mysqli_stmt_store_result() every query ..., if , if want buffer complete result set client ..."


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -