How to run the bind_param() statement in PHP?(如何在 PHP 中运行 bind_param() 语句?)
问题描述
我正在尝试使以下代码工作,但无法到达 execute()
行.
I'm trying to make the following code work but I can't reach the execute()
line.
$mysqli = $this->ConnectLowPrivileges();
echo 'Connected<br>';
$stmt = $mysqli->prepare("SELECT `name`, `lastname` FROM `tblStudents` WHERE `idStudent`=?");
echo 'Prepared and binding parameters<br>';
$stmt->bind_param('i', 2 );
echo 'Ready to execute<br>'
if ($stmt->execute()){
echo 'Executing..';
}
} else {
echo 'Error executing!';
}
mysqli_close($mysqli);
我得到的输出是:
Connected
Prepared and binding parameters
所以问题应该在第 5 行,但检查 bind_param()
手册我在那里找不到任何语法错误.
So the problem should be at line 5, but checking the manual of bind_param()
I can't find any syntax error there.
推荐答案
绑定参数时需要传递一个变量作为引用:
When binding parameters you need to pass a variable that is used as a reference:
$var = 1;
$stmt->bind_param('i', $var);
参见手册:http://php.net/manual/en/mysqli-stmt.bind-param.php
注意 $var
实际上并不需要定义来绑定它.以下是完全有效的:
Note that $var
doesn't actually have to be defined to bind it. The following is perfectly valid:
$stmt->bind_param('i', $var);
foreach ($array as $element)
{
$var = $element['foo'];
$stmt->execute();
}
这篇关于如何在 PHP 中运行 bind_param() 语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 PHP 中运行 bind_param() 语句?


基础教程推荐
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01