db类选择不按预期输出

时间:2015-05-09 21:17:00

标签: php class

我正在尝试在使用类时从db输出一个值,如下面代码底部所示。

但这并没有按预期输出值。

我对课程非常陌生,只是看不出我错在哪里

$getx = new getx();

class getx extends hush { 
    public function username($uidr) {
       global $dbx;

       $usernameR = $dbx->qry(" SELECT username FROM exp_members WHERE member_id = '$uidr' ");

       $row = mysql_fetch_array($usernameR, MYSQL_ASSOC);

       return $usernamex = $row['username'];

    }
    public function email($uidr) {  
       global $dbx;

       $emailR = $dbx->qry(" SELECT email FROM exp_members WHERE member_id = '$uidr' ");

       $row2 = mysql_fetch_array($emailR, MYSQL_ASSOC);

       return $email = $row2['email'];

    }

} 

echo $username = $getx->username(1); // this is not working as expected

错误: Fatal error: Call to a member function qry() on a non-object in..

@ this point $usernameR = $dbx->qry(" SELECT username FROM exp_members WHERE member_id = '$uidr' ");

处理db

的部分
//database x credentials
$dbx = new queryx("localhost","xxx","xxx","xxx");

class queryx extends hush { //queryx is the query port for the cms 
    public function __construct($host,$user,$pass,$dbname) {
        mysql_connect($host,$user,$pass)
            or die(mysql_error());
        mysql_select_db($dbname)
            or die(mysql_error());
    }
    public function qry($sql) {
       // return mysql_query($sql);
            $query = mysql_query($sql) or die(mysql_error());
            return $query;  
    }

} 

0 个答案:

没有答案