简体   繁体   中英

MySQLi prepared statement not returning

I am learning PHP and I am trying to use prepared statements with MySQLi. I know my SQL returns exactly what I want, it returns in PHPmyAdmin just fine, just not in PHP.

    $stmt=mysqli_stmt_init($mysql);
$query = "SELECT name,version,category FROM `software` WHERE id =?";

$stmt = mysqli_stmt_prepare($mysql, $query);

mysqli_stmt_bind_param($stmt, 'i', $sid);

mysqli_stmt_execute($stmt);

mysqli_stmt_bind_result($stmt, $name, $version, $category);

mysqli_stmt_fetch($stmt);

if (empty($name)){die("No results found.");};

echo "<center><h1><b>" . $name . "</b></h1><br />";

I know $sid = 1, because I can echo that and it is set, I can also remove the bind params and just set the ? to 1 and same result.

Any help would really be appreciated, thank you!

$stmt=mysqli_stmt_init($mysql);
$query = "SELECT name,version,category FROM `software` WHERE id =?";

$stmt = mysqli_stmt_prepare($mysql, $query);

mysqli_stmt_bind_param($stmt, 'i', $sid);

mysqli_stmt_execute($stmt);

mysqli_stmt_bind_result($stmt, $name, $version, $category);

///try the while
while (mysqli_stmt_fetch($stmt)) {
    printf ("%s (%s)\n", $name, $version, $category);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM