-1

Who can give me an advice? why the query can't to provide me an expected value? Thanks.

 $mysqli = new mysqli($GLOBALS["mysql_host"], $GLOBALS["mysql_user"],          $GLOBALS["mysql_passwd"], $GLOBALS["mysql_database"]);
 $stmt = $mysqli->prepare("SELECT one FROM table ORDER BY date DESC LIMIT 1");
 $last = $stmt->bind_result($one);
 $stmt->execute();
 $stmt->close();
 $mysqli->close();

 Echo $last; //it should be "abc"
wing suet cheung
  • 205
  • 2
  • 5
  • 10
  • Your question is "who can give me advice?". Well, only someone who understands what you need. For that, your question needs to be less vague. – aravk33 Sep 29 '17 at 10:45

2 Answers2

5

I think you have to execute and then call fetch on mysql_stmt-objects. Because you may get multiple results (rows).

With fetch you will advance your 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 FROM Country ORDER BY Name LIMIT 5")) {
    $stmt->execute();

    /* bind variables to 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();

?>
mo.
  • 3,474
  • 1
  • 23
  • 20
0

I can.
An advise would be plain and simple: do not use mysqli

Use PDO instead

$stmt = $pdo->prepare("SELECT one FROM table ORDER BY date DESC LIMIT 1");
$stmt->execute();
$last = $stmt->fetchColumn();

echo $last; //it should be "abc"

clean, simple and works

Community
  • 1
  • 1
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 1
    What's wrong with MySQLi? – gen_Eric Apr 18 '13 at 14:16
  • 1
    indeed, i would prefer PDO too. It has a nice level of abstraction. There is a [nice explanation at nettuts](http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/) – mo. Apr 19 '13 at 12:42