gpt4 book ai didi

php - 出现错误 - 警告:DbQuery::__construct() 缺少参数 1

转载 作者:搜寻专家 更新时间:2023-10-30 23:02:34 24 4
gpt4 key购买 nike

我正在使用以下代码来创建与数据库的连接。但是给我的错误是 Warning: Missing argument 1 for DbQuery::__construct();

请给我解决方案并指出我的错误。以下是我的代码:

核心.php

    //Database connection
class DbQuery{
public $conn;
private $host;
private $user;
private $pass;
private $daba;

public function __construct($ihost, $iuser, $ipass, $idaba){
$this->host = $ihost;
$this->user = $iuser;
$this->pass = $ipass;
$this->daba = $idaba;

$this->conn = new mysqli($this->host, $this->user, $this->pass, $this->daba);

if($this->conn->connect_errno){
die("Failed to connect with database : (" . $this->conn->connect_errno . ")" . $this->conn->connect_errno);
}
}
}
class GenQuery extends DbQuery{
//EXECUTE QUERY
function exeQuery($input){
$result = mysqli_query($this->conn, $input);
if(!$result){
die("Invalid query : ". mysqli_error($this->conn));
}
return $result;
}
//SELECT QUERY
function selQuery($selectItem, $tableName, $condName, $condValue){
$n = sizeof($selectItem);
$m = sizeof($condValue);
$l = sizeof($condName);

if($m == $l){
for($j=0; $j<$n; $j++){
if($j == 0){
$selectVal = $selectItem[$j];
}
else{
$selectVal .= ", " . $selectItem[$j];;
}
}

for($i=0; $i<$m; $i++){
if($i == 0){
$val = $condName[$i] . " = '" . $condValue[$i] . "'";
}
else{
$val .= " AND " . $condName[$i] . " = '" . $condValue[$i] . "'";
}
}
$query = "SELECT " . $selectVal . " FROM " . $tableName . " WHERE " . $val;
$result = $this->exeQuery($query);
return $result;
}
}
}

class ProcessQuery extends GenQuery{
function selUser($condValue){
$selectItem = array('*');
$condName = array('uid');
$input = $this->selQuery($selectItem, 'mk_user', $condName, $condValue);
if(mysqli_num_rows($input) > 0){
while($frow = mysqli_fetch_assoc($input)){
$res = $frow['uname'];
}
return $res;
}
}
}

测试.php:

    <?php

require 'core.php';
$db = new DbQuery('localhost', 'root', '', 'mkart');
$b = ['12'];
$qry = new processQuery();
echo $res = $qry->selUser($b);

?>

提前致谢。

最佳答案

这一行是你的问题:

$qry = new processQuery();

在你的类里面 processQuery扩展(间接)DBQuery . DbQuery 构造函数由 processQuery 继承$ihost 需要四个参数, $iuser , $ipass$idaba ,但是在实例化 processUser 时没有提供任何信息.

您在实例化 $db 时提供参数两行之前,但那是一个不同的对象,并且 $qry不从它继承。

你可能需要

$qry = new processQuery('localhost', 'root', '', 'mkart');

关于php - 出现错误 - 警告:DbQuery::__construct() 缺少参数 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30159973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com