我的数据库连接代码是
public function open()
    {
    $db = new Data_Mysql();
    return $db;
    }
   
   function __construct($pconnect = 0)
    {    
try {

    $func = $pconnect==0 ? 'mysql_connect' : 'mysql_pconnect';
   
    $this->link = @$func($this->dbhost, $this->dbuser, $this->dbpw, 1);
   
    $charset1 = $this->dbcharset == '' ? $this->charset : "GB2312";
   
    if(!empty($charset1))
    {
    if(function_exists('mysql_set_charset'))
    {
    @mysql_set_charset($charset1, $this->link);
    }
    else 
    {
    $collation_query = "SET NAMES '{$charset1}'";
    $this->Query($collation_query);
    }
    }
   
    $this->dbname && @mysql_select_db($this->dbname, $this->link);
   
    } catch (Exception $e) {
   
    if ($this->errno())
    {
    throw new Common_MyException("Can't connect to database./数据库服务器连接失败 ");
    }
    }

   }
   
   function Query($sql)//执行代码
   {
     try
     {
     if(!($result = @mysql_query($sql, $this->link)))
     {
     throw new Common_MyException($this->error());
     }
     }
     catch (Common_MyException $e)
     {
     die($e->showStackTrace());
     }
        return $result;
       
    }
    
function __destruct()//断开连接
    {
    if (!$this->errno())
    {
    $this->close();
    }
   }
    //释放结果集所占用的内存
function free_result($query) {
return mysql_free_result($query);
}

   //返回多条记录
public function FetchAll($sql)
   {
   $returnRows=array();
     try
     {
     if($sql==null) {
    
     throw new MyException("查询语句为空.");  
     }
     if(!($result = $this->Query($sql)))
     {
     throw new Common_MyException($this->error());
     }
     while ($rows=$this->fetch_array($result)) 
   {  
   $returnRows[]=$rows;
   }
   return $returnRows;
  
     }
     catch (Common_MyException $e)
     {
     die($e->showStackTrace());
     }
}

function FetchRow($sql)//返回单条记录
   {
   $rows=null;
  
     try
     {
     if($sql==null || $sql=="") {
     throw new MyException("查询语句为空.");
     }
    
     if(!($result = $this->Query($sql)))
     {
     throw new Common_MyException($this->error());
     }
     $rows = $this->fetch_array($result);
    
     }
     catch (Common_MyException $e)
     {
     die($e->showStackTrace());
     }
     return $rows;

  
function error() {
return (($this->link) ? mysql_error($this->link) : mysql_error());
}

function errno() {
return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());
}

function select_db($dbname) {
return mysql_select_db($dbname, $this->link);
}

function close() {
return mysql_close($this->link);
}

function num_rows($query) {
$query = mysql_num_rows($query);
return $query;
}

function result($query, $row = 0) {
$query = @mysql_result($query, $row);
return $query;
}

function insert_id() {
return ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);
}

function fetch_array($query, $result_type = MYSQL_ASSOC) {
return mysql_fetch_array($query, $result_type);
}可是网站都是频繁报错
Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 37Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 62
或者
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 151
哪位高手能帮我解决下呀,小弟在这不胜感激

解决方案 »

  1.   

    检查一下你的MYSQL错误日志,看看其中是什么信息。一种可能就是防火墙。
      

  2.   

    这个检查的目的就是想判断故障点在MYSQL服务器端还是程序端。
      

  3.   

    InnoDB: The first specified data file .\ibdata1 did not exist:
    InnoDB: a new database to be created!
    100419  1:30:31  InnoDB: Setting file .\ibdata1 size to 10 MB
    InnoDB: Database physically writes the file full: wait...
    100419  1:30:31  InnoDB: Log file .\ib_logfile0 did not exist: new to be created
    InnoDB: Setting log file .\ib_logfile0 size to 23 MB
    InnoDB: Database physically writes the file full: wait...
    100419  1:30:32  InnoDB: Log file .\ib_logfile1 did not exist: new to be created
    InnoDB: Setting log file .\ib_logfile1 size to 23 MB
    InnoDB: Database physically writes the file full: wait...
    InnoDB: Doublewrite buffer not found: creating new
    InnoDB: Doublewrite buffer created
    InnoDB: Creating foreign key constraint system tables
    InnoDB: Foreign key constraint system tables created
    100419  1:30:32  InnoDB: Started; log sequence number 0 0
    100419  1:30:32 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: ready for connections.
    Version: '5.0.45-community-nt'  socket: ''  port: 3306  MySQL Community Edition (GPL)
    100420 13:40:35 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: Normal shutdown100420 13:40:35  InnoDB: Starting shutdown...
    100420 13:40:39  InnoDB: Shutdown completed; log sequence number 0 160805925
    100420 13:40:39 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: Shutdown complete100420 13:45:31  InnoDB: Started; log sequence number 0 160805925
    100420 13:45:32 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: ready for connections.
    Version: '5.0.45-community-nt'  socket: ''  port: 3306  MySQL Community Edition (GPL)
    MYSQL里的日志是这样的,我也看不懂,能帮我解释下吗?是代码问题还是程序问题呀