- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用以下代码来创建与数据库的连接。但是给我的错误是 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/
我有一个对结果进行分组的 Entity Framework 查询,我想将其传递给 View ,但我无法将其正确转换到 View 模型! (我想在 View 的网格中显示结果) 如果我使用这个类型转换
我有一个 DbQuery,我想用我的 DbQuery 项填充另一个列表,条件如下: var carsList= DbContext.Cars.Where(e=> e.brand == brand);
我正在努力解决一个问题,我必须能够有效地从数据库中检索数据。 我正在使用 EF 4.3/c#。 这是我拉回数据的 EF 逻辑: IEnumerable GetHotOffers() { usi
我想知道是否有人可以阐明这里可能发生的事情。我正在使用 C#、MVC 和 Entity Framework 。 所以我运行这两行代码: var booboo = _context.AppItems.W
我在 mongodb 控制台中运行这段代码: var participantsWithoutCategory = db.participant.find({eventId: ObjectId("536
跟进这个问题/答案 How to make Entity Framework Data Context Readonly 解决方案是创建 DbQuery 类型的 DbContext 集合,但这是一个相
如果我使用下面的代码,我会得到学习类(class) 1 和类(class) 2 的学生列表。(这几乎是我想要的。) IQueryable filteredStudents = context.Stud
我有两个表: products: id, name, manufacturer myproducts:id, user_id, product_id 我通过我的授权 token 知道 user_id。
免责声明:我无法从 another question 中找到所有答案在 SO 上。 在 LINQPad 中准备查询时,我观察到一些结果返回为 IQueryable在 DbSet 中的一些地方. 查询的
我有使用 linq 语句获取查询的代码,使其成为 DbQuery 而不是 ObjectQuery 并且我使用该查询通过 foreach 循环添加参数。但是 DbQuery 没有参数支持。我知道我可以手
我有一个DBQuery其转换为 IQueryable (这一点工作正常)。但后来我尝试将 IQueryable 转换为 ObjectQuery .. 失败了:- public void Foo(thi
使用 Django 博客,我有一个如下所示的模板: {{ post.title }} 这看起来无伤大雅,但它最终会生成对博文用户的又一次查找,这是我(在大多数情况下)已经知道的。然而,这不是我的意思。
我正在使用以下代码来创建与数据库的连接。但是给我的错误是 Warning: Missing argument 1 for DbQuery::__construct(); 请给我解决方案并指出我的错误。
这是 EF6。我可以在我的查询中包含 .Include() 方法(没有双关语),以便从相关表中预先加载信息。但是看起来 .Include() 方法只接受一个字符串参数。有没有办法以强类型的方式做到这一
我刚刚为一个使用 EntityFramework 的新项目声明了一些代码优先模型。 public class BlogEntry { public long Id { get; set; }
我有这个查询字符串: coll.find(and(DBQuery.greaterThanEquals("createdOn", startDate), DBQuery.lessThanEquals("
我在 visual studio 2012 上编码并使用实体模型 作为我的数据层。但是,当页面尝试加载(上面的标题)时,我使用 Linq 语句的下拉控件往往会引发未处理的异常。下面是我的代码; usi
我有以下代码: public void DeleteAccountsForMonth(int year, int month) { var result = from acm in this.
我遇到了一种情况,我尝试在网上找到解决方案,但没有成功。我是使用 Entity Framework 的 MVC 新手,当我尝试运行应用程序时它抛出异常: The model item passed i
我正在使用 EF,我有以下代码,我在其中尝试从名为 interface5toSSHIP 的 View 中获取行。 SQL Explorer 显示数据库 View 现在只有一行。以下查询似乎没有返回它。
我是一名优秀的程序员,十分优秀!