php - Mysql prepare statement - Select -


who can give me advice? why query can't provide me expected value? thanks.

 $mysqli = new mysqli($globals["mysql_host"], $globals["mysql_user"],          $globals["mysql_passwd"], $globals["mysql_database"]);  $stmt = $mysqli->prepare("select 1 table order date desc limit 1");  $last = $stmt->bind_result($one);  $stmt->execute();  $stmt->close();  $mysqli->close();   echo $last; //it should "abc" 

i think have execute , call fetch on mysql_stmt-objects. because may multiple results (rows).

with fetch advance result-cursor.

documentation: mysqli mysqli-stmt

<?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world");  if (mysqli_connect_errno()) {     printf("connect failed: %s\n", mysqli_connect_error());     exit(); }  /* prepare statement */ if ($stmt = $mysqli->prepare("select code, name country order name limit 5")) {     $stmt->execute();      /* bind variables prepared statement */     $stmt->bind_result($col1, $col2);      /* fetch values */     while ($stmt->fetch()) {         printf("%s %s\n", $col1, $col2);     }      /* close statement */     $stmt->close(); } /* close connection */ $mysqli->close();  ?> 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -