[英]where clause variable malfunctioning
我是oop環境的新手,這里似乎不正確,我已經搜索了所有內容,但可用的是在類內部提供了查詢字符串。
if(isset($_POST['search'])){
include('../Classes/class.config.php');
include('../Classes/class.dbActions.php');
$execute=new execute();
$execute->select('SELECT * FROM users where username="'.$_POST['search'].'" ');
$array=$execute->Fetch();
echo $array['chasisNo'].'<br/>';
}
當我改變時:
$execute->select('SELECT * FROM users where username="'.$_POST['search'].'" ');
對此
$execute->select('SELECT * FROM users ');
通過列出頂部它可以完美地工作
現在,即使我傳遞了像
$execute->select('SELECT * FROM users where username="oketch" ');
這是行不通的
這是執行類
class execute extends db
{
private $sqlString;
private $selected;
private $querySelected;
public function select($sqlString)
{
$connection=$this->getConnection();
$this->querySelected=$connection->query($sqlString);
if($this->querySelected->num_rows>0) {
$this->Fetch();
}
else {
echo'No Data Available';
}
}
public function Fetch() {
return $this->querySelected->fetch_array();
}
您正在執行$this->Fetch();
在select()
內部。 我假設這將獲取結果集的一行。 然后,您執行后續的$execute->Fetch()
來實際獲得所需的結果。
如果沒有WHERE
子句,則可能會有多行。 第一個結果行被select()
內的Fetch()
消耗並以太坊。 然后,您檢索第二行並顯示它。
使用WHERE
子句,只有一行被消耗到以太中,然后就沒有實際的行要提取和顯示了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.