开发者

MySQLi not returning results from database

This is my code:

<?php

include('config.php');

$mysqli = new mysqli($db['host'], $db['user'], $db['pass'], $db['name']);
if ($mysqli->connect_error)
    throw new Exception('Couldn\'t connect to MySQL: ' . $mysqli->connect_error);

// Check for a ID parameter
if(isset($_GET['id']) && !empty($_GET['id']))
{
    $skinId = (int)$_GET['id'];

    // Build a query to get skin info from the database
    $stmt = $mysqli->prepare('SELECT name, description, author, timestamp, url FROM `skins` WHERE id=?');
    $stmt->bind_param('i', $skinId);

    // Execute query
    $stmt->execute();
    $stmt->bind_result($result['name'], $result['desc'], $result['auth'开发者_Python百科], $result['time'], $result['url']);

    echo $result['name'];
} else {
    // Show a 404 page
    echo "bad";
}

$mysqli->close();

?>

When this is run, I get no results back. I can verify that $skinId does hold a valid skin ID when I try, and it's not an empty variable. When I run the same statement on localhost using phpMyAdmin, I get the proper row back with all the information requested in the query. When I do print_r($result) I get this:

Array
(
    [name] => 
    [desc] => 
    [auth] => 
    [time] => 
    [url] => 
)

Anyone know what's going on? Thanks in advance. :)


you should do $stmt->fetch() after the $stmt->bind_result command in order to fetch the data from the database to the your result array

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜