【发布时间】:2011-05-16 17:02:50
【问题描述】:
这是我的代码:
<?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'], $result['time'], $result['url']);
echo $result['name'];
} else {
// Show a 404 page
echo "bad";
}
$mysqli->close();
?>
当它运行时,我没有得到任何结果。我可以验证$skinId 在我尝试时确实持有有效的皮肤 ID,并且它不是一个空变量。当我使用 phpMyAdmin 在 localhost 上运行相同的语句时,我得到了正确的行,其中包含查询中请求的所有信息。当我做print_r($result) 时,我得到了这个:
Array
(
[name] =>
[desc] =>
[auth] =>
[time] =>
[url] =>
)
有人知道发生了什么吗?提前致谢。 :)
【问题讨论】:
-
你确定id在数据库里吗?