dtf0925 2012-09-27 12:37
浏览 59
已采纳

在php中连接到mysql时,query_id没有返回任何内容

My query is:

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

i am usign XAMPP as apache server and i am working on port (89)

this class responsible for database connection:

<?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;
    }
}   
?>

this code for connecting to the mysql dbms and execute queries. when printing $_link_Id ,it has a value. when printing $_query_Id ,it has nothing ?

  • 写回答

3条回答 默认 最新

  • dsfsda121545 2012-09-27 12:39
    关注

    Problem is here

    $sqlcommand= addslashes($sqlcommand);
    

    Don't use addslashes.

    use like this

    //$sqlcommand= addslashes($sqlcommand);
    $this->_query_Id=mysql_query($sqlcommand,$this->_link_Id);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改