【发布时间】:2012-09-05 16:58:20
【问题描述】:
我有下一个代码,用于创建 mysqli 对象并准备查询:
$GLOBALS['DB_something'] = new mysqli('$database_hostname','$database_username','$database_password','$database_default');
$GLOBALS['DB_prepared_get'] = $GLOBALS['DB_something']->prepare("SELECT ? from database_name WHERE hash=?");
和下一个代码,获取并显示结果。由于我最近没有进入准备好的语句,特别是没有使用 PHP,我不知道如何从中得到结果。
当我在没有准备好的语句的情况下编写代码时,它可以工作,但由于很多原因,我需要用准备好的语句重写它。
$GLOBALS['DB_prepared_get']->bind_param('ss', $arg, $index);
$GLOBALS['DB_prepared_get']->execute();
$GLOBALS['DB_prepared_get']->bind_result($result); # this is an array of values
$GLOBALS['DB_prepared_get']->fetch();
# below this, I don't know if it's ok
if(mysql_num_rows($result) == 0){
return "0";
}
else{
while($GLOBALS['DB_prepared_get']->fetch()) {
return $result;
}
}
$GLOBALS['DB_prepared_get']->close();
感谢您的帮助。
编辑:为了清楚起见,我的问题是如何获取确切的结果值以将它们打印出来或其他东西。所以语法是我可能做错的。
【问题讨论】:
-
选择是什么,准备好的语句不适用于第一个?参数如果我没记错的话,你必须明确地写出来
-
准备好声明的意义何在? :(
-
安全有时是性能,您将更改的值是 SELECT * FROM table WHERE id=? ,而您使用 ?对于倍数 ID
标签: php mysqli prepared-statement