php statement question. (mysqli)

流过昼夜 提交于 2019-12-25 08:42:19

问题


$db = new mysqli('localhost','root','nere','deneme');

if ($db->error)
exit();

$stmt = $db->prepare("INSERT INTO deneme VALUES (?,?,?)");

$stmt->bind_param('ssi',$adi,$soyadi,$no);

$adi='recep';
$soyadi='saban';
$no=5;

$stmt->execute();

i got error.

Fatal error: Call to a member function bind_param() on a non-object in C:\wamp\www\rock\index.php on line 10

what I am doing wrong?


回答1:


it should be something like below. Also you should assign the values to the variables before passing it to bind_param()

if ($db->error)
exit();

if ($stmt = $db->prepare("INSERT INTO deneme VALUES (?,?,?)")) {
$adi='recep';
$soyadi='saban';
$no=5;

$stmt->bind_param('ssi',$adi,$soyadi,$no);


$stmt->execute();
}

It's also a good idea to tell which columns should be populated in your database:

INSERT INTO deneme (column1, column2, column3) VALUES (?,?,?)



回答2:


Looks like your prepare statement is failing, and $stmt is false (you should add some checking there). Does table deneme actually exists?



来源:https://stackoverflow.com/questions/6056838/php-statement-question-mysqli

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!