我有 Afactory mysql 简单类,我可以使用这种方法:
Afactory.class.php
:
require_once ( substr( dirname(__FILE__), 0, -5 ).'config.inc' );
class AFactory
{
private $DBhost;
private $DBuser;
private $DBpass;
private $DBname;
private $DBport;
private $queryResult;
private $linkConnection;
public function __construct()
{
$this->DBhost=LOCALHOST;
$this->DBuser=USERNAME;
$this->DBpass=PASSWORD;
$this->DBname=DATABASE;
}
public function getDBO()
{
$linkConnection = mysql_connect ($this->DBhost , $this->DBuser , $this->DBpass);
mysql_query("set charset set utf8", $linkConnection);
mysql_query("set names 'utf8'", $linkConnection);
return mysql_select_db($this->DBname) ? TRUE : FALSE;
}
public function setQuery($query)
{
return mysql_query($query);
}
public function loadAssoc()
{
$array=NULL;
while($result = mysql_fetch_assoc($this->queryResult ))
$array[] = $result;
return $array;
}
}
有了这个文件,我可以使用类和类的功能
文本.php:
$db=new AFactory();
$link=$db->getDBO();
$db->loadAssoc($db->setQuery("SELECT * FROM users")); // this can return array
我想创建新类并使用 Afactory 类
测试类.php:
include ( substr( dirname(__FILE__), 0, -5 ).'alachiq_settings.php' );
class alachiq extends AFactory{
public function __construct() {
parent::__construct();
}
public function fetchArray(){
echo parent::getDBO(); //this line can return successfull connect to db
return parent::loadAssoc(parrent::setQuery("SELECT * FROM users")); //fetch sql command
}
}
在使用 Afactory 扩展创建 alachiq 类后,我无法使用此方法:
使用测试类:
include('testclass.php');
print_r( alachiq::fetchArray() );
我的代码问题是什么?