0
我得到這個錯誤的:致命錯誤:調用一個成員函數查詢()非對象
SQLSTATE[] (null) (severity 0) Fatal error: Call to a member function query() on a non-object in /.../functions.php on line 50
線50:
foreach($this->sqlDbKowsar->dbh->query($sql) as $row)
DB_Functions
類:
<?php
class DB_Functions {
private $sqlDbKowsar;
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$this->sqlDbKowsar = new DB_Connect();
$this->sqlDbKowsar->connect();
}
// destructor
function __destruct() {
}
function getSimpleSearch($title,$cat,$start_end){
$start_and_end = explode("-",$start_end);
$cat = $this->getCategories($cat);
$array_of_cat = explode(",",$cat);
$sql = "select * from (
select *,ROW_NUMBER() OVER (ORDER BY GoodMainCode) as row from [SarMem].[dbo].[Book_Data1] WHERE GoodName LIKE ' %$title% ' and
GroupCode IN (" . implode(",",$array_of_cat) . ")) a
where a.row > $start_and_end[0] and a.row <= $start_and_end[1] ";
$mjson = array();
foreach($this->sqlDbKowsar->dbh->query($sql) as $row){
$arr = array(
'GoodMainCode'=>persian_sql_to_php($row['GoodMainCode'])
);
array_push($mjson,$arr);
}
//added
foreach($mjson as $v){
if(!isset($result[$main_good_code = $v['GoodMainCode']])){
$result[$main_good_code = $v['GoodMainCode']] = $v;
}
else
$result[$main_good_code = $v['GoodMainCode']]['amount'] += $v['amount'];
}
return $result ;
}//end simple search function
}
?>
DB_Connect
等級:
class DB_Connect {
public $dbh;
// constructor
function __construct() {
}
// destructor
function __destruct() {
// $this->close();
}
// Connecting to database
public function connect() {
require_once 'config.php';
try {
$hostname = DB_HOST ;
$dbname = DB_DATABASE;
$port = 1433;
$this->dbh = new PDO ("dblib:host=$hostname;dbname=$dbname;charset=UTF-8",DB_USER, DB_PASSWORD);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
我的錯誤是什麼?
這是什麼'的var_dump($這個 - > sqlDbKowsar->胸徑);'輸出ķ – D4V1D
@ D4V1D:沒有! –
* Nothing *不是PHP中的一種變量。是'null','empty','string'等? – D4V1D