1

私の質問は:

$sqlCommand="select `ID` from `freecomputermarket`.`members` where `UserName`='$this->_userName';";

私はApacheサーバーとしてXAMPPを使用しており、ポート(89)で作業しています。

データベース接続を担当するこのクラス:

<?php
class MySql
{
    private $_link_Id,$_query_Id,$_serverName,$_userName,$_password,$_dbName,$_rowNum;

    public function __construct()
    {
       $this->_serverName="localhost";
       $this->_userName="root";
       $this->_password="";
       $this->_dbName="freecomputermarket";
    }
    public function connect()
    {
       $this->_link_Id=mysql_connect($this->_serverName,$this->_userName,$this->_password);
       if(!$this->_link_Id)
       {
          exit("The Connect is Failed");
       }
       $db_select=mysql_select_db($this->_dbName,$this->_link_Id);
       if(!$db_select)
       {
          exit("Can't Select DataBase");
       }
    }
    public function query($sqlcommand)
    {
       $sqlcommand= addslashes($sqlcommand);
       //echo $sqlcommand;
       $this->_query_Id=mysql_query($sqlcommand,$this->_link_Id);
       exit($this->_query_Id);//print it to check if it is available.
       if(!$this->_query_Id)
          exit("Query failed");
       $this->_rowNum=mysql_affected_rows();
    }
    public function getRow()
    {
       if($this->_rowNum)
       {
          return mysql_fetch_assoc($this->_query_Id);
       }
    }
    public function getAllRows()
    {
       $arr=array();
       $count=0;
       while($count<$this->_rowNum)
       {
          array_push($arr,$this->GetRow());
          $count++;
       }
       return $arr;
    }
    public function getAffectedRowsNumber()
    {
       return $this->_rowNum;
    }
}   
?>

mysql dbmsに接続し、クエリを実行するためのこのコード。$ _link_Idを出力する場合、値があります。 $ _query_Idを出力するとき、何もありませんか?

4

3 に答える 3

0

問題はここにあります

$sqlcommand= addslashes($sqlcommand);

アッドラッシュは使用しないでください。

このように使用する

//$sqlcommand= addslashes($sqlcommand);
$this->_query_Id=mysql_query($sqlcommand,$this->_link_Id);
于 2012-09-27T12:39:24.307 に答える
0
<?php
class MySql
{
    private $_link_Id,$_query_Id,$_serverName,$_userName,$_password,$_dbName,$_rowNum;

    public function __construct()
    {
        $this->_serverName="localhost";
        $this->_userName="root";
        $this->_password="";
        $this->_dbName="freecomputermarket";
    }
    public function connect()
    {
        $this->_link_Id=mysql_connect($this->_serverName,$this->_userName,$this->_password);
        if(!$this->_link_Id)
        {
                                                exit("The Connect is Failed");
        }
        $db_select=mysql_select_db($this->_dbName,$this->_link_Id);
        if(!$db_select)
        {
                                                exit("Can't Select DataBase");
        }
    }
    public function query($sqlcommand)
    {
                                        // $sqlcommand= addslashes($sqlcommand);
                                          //echo $sqlcommand;
        $this->_query_Id=mysql_query($sqlcommand,$this->_link_Id);
                                          exit($this->_query_Id);//print it to check if it is available.
        if(!$this->_query_Id)
                                                exit("Query failed");
        $this->_rowNum=mysql_affected_rows();
    }
    public function getRow()
    {
        if($this->_rowNum)
        {
                                                return mysql_fetch_assoc($this->_query_Id);
        }
    }
    public function getAllRows()
    {
        $arr=array();
        $count=0;
        while($count<$this->_rowNum)
        {
                                                array_push($arr,$this->GetRow());
                                                $count++;
        }
        return $arr;
    }
                    public function getAffectedRowsNumber()
                    {
                        return $this->_rowNum;
                    }
}   
?>

addlashes()関数が問題です

于 2012-09-27T13:09:16.347 に答える
0

問題は、スコープで接続を開始しなかったパブリック関数query($ sqlcommand)にあります。関数query($ sqlcommand)でconnect()を開始する必要があります

于 2012-09-27T13:12:25.253 に答える