[英]Issue with mysqli in PHP Warning: mysqli_stmt_prepare() expects parameter 1
I have been looking at this code for a while and can't figure out where the problem is.我一直在看这段代码,但无法弄清楚问题出在哪里。
I am new to coding in general, but especially new to CRUD
and SQL
.我一般不CRUD
编码,但对CRUD
和SQL
尤其CRUD
。 I want to create a prepared statement here to use variables instead of exact values.我想在这里创建一个准备好的语句来使用变量而不是精确值。 I don't understand where the issue comes from我不明白问题从何而来
I have a Databasetools.php我有一个 Databasetools.php
<?php
class DatabaseTools
{
//private $user = $_SESSION['userId']; // these get called when the object gets created
//private $userEmail = $_SESSION['emailUser'];
public function __construct($Name)
{
$servername = "localhost";
$dBUsername = "root";
$dBPassword = "supersecretpassword";
$dbPort = "3306";
$this->name = $Name;
$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $this->name, $dbPort);
$stmt = mysqli_stmt_init($conn);
if(!$conn)
{
die("connection faild: ".mysqli_connect_error());
}
}
public function lookup($dBName, $Row, $Column)
{
//$sql = "SELECT ".$Column." FROM ".$dBName." WHERE ".$Row.";";
$sql = "SELECT ? FROM ? WHERE ?;";
if(!mysqli_stmt_prepare($stmt, $sql))
{
echo "False";
}
else
{
mysqli_stmt_bind_param($stmt, "sss", $column, $dBName, $Row);
mysqli_stmt_execute($stmt);
$result = mysli_stmt_get_result($stmt);
echo $result;
}
// try to connect to the database
}
public function setCell($Database, $Row, $Column)
{
}
public function disconnect($dBName)
{
}
public function echotest()
{
}
}
?>
And I am using a page to check if the code is working我正在使用一个页面来检查代码是否有效
<?php
require "Model/php/databaseTools.php";
$loginData = new databaseTools("loginsystem");
$loginData->lookup("loginsystem","*","*");
?>
Thanks so much if you could point me in the write direction.如果你能指出我的写作方向,非常感谢。
Are you sure you have $stmt value in the lookup function?您确定在查找函数中有 $stmt 值吗?
Try to add it as one of the parameters, something like this:尝试将其添加为参数之一,如下所示:
public function lookup($dBName, $stmt, $Row, $Column)
and then call it also with $stmt
parameter:然后也用$stmt
参数调用它:
$loginData->lookup("loginsystem", <stmt> ,"*","*");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.