php – bind_param()似乎不起作用

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – bind_param()似乎不起作用脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下代码

<?PHP
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';
$db = new MysqLi($dbhost,$dbuser,$dbpass,'images_db');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
else{
echo "Connected to database";
}
//filename,mime_tyPE and file_size are columns in the table images
$stmt = $db->PRepare("INSERT INTO images (filename,mime_type,file_size) VALUES (?,?,?)");
$string1 = 'string 1';
$string2 = 'string 2';
$stmt->bind_param('ssi',$string1,$string2,123);
$stmt->execute();
$stmt->close();
$MysqLi->close();
?>

当我执行代码时,没有任何东西被添加MysqL数据库中.但是当我评论出这条线时

$stmt->bind_param('ssi',123);

并将字符串和整数值直接插入$db-> prepare语句(替换问号),这一切都很好用,并将行添加数据库表中.

我在bind_param行中做错了什么,阻止将新行添加数据库中?

解决方法

mysqli_stmt_bind_param接受变量(通过引用).你不能使用文字.将您的代码改为

$fileSize = 123;
$stmt->bind_param('ssi',$fileSize);

脚本宝典总结

以上是脚本宝典为你收集整理的php – bind_param()似乎不起作用全部内容,希望文章能够帮你解决php – bind_param()似乎不起作用所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。