我用PHPLIB的模块。其它的都没有用~~~~~~~~~

解决方案 »

  1.   

    $my_db = new DB_Sql();
      $my_db->connect($db_table,$db_host,$db_user,$db_psw);
      $q = "SELECT * FROM `guestbook` ";
      $my_db->query($q);
      if($my_db->next_record()){
        echo "no record";
      }else{
        echo $my_db->Record["name"];";
      }
    这样子看看。
    你报的是什么错误呢?你也没有说。
      

  2.   

    我都是自己写类的:
    class DB
    {
    /* host name
    * @var: string
    */
    var $_host = ''; /* username
    * @var: string
    */
    var $_user = ''; /* password
    * @var: string
    */
    var $_pass = ''; /* database name
    * @var: string
    */
    var $_db = ''; /* debugging true or false: default false */
    var $debugging = false; /*
    * construct function
    */
    function DB()
    {
    global $XeroxConfig;
    $this->_host = $XeroxConfig['MysqlHostname'];
    $this->_user = $XeroxConfig['MysqlUsername'];
    $this->_pass = $XeroxConfig['MysqlPassword'];
    $this->_db  = $XeroxConfig['MysqlDatabase'];
    } /*
    * Debug function
    */
    function debug($str, $file, $line)
    {
    if ($this->debugging)
    {
    if (is_array($str))
    {
    print_r($str);
    } else {
    $debug = "Debug Info: $str (<font color=#0000FF>$file</font> ".
     "on line <font color=#FF0000>$line</font>)<br>\n";
    print($debug);
    }
    }
    } /*
    * Error function
    */
    function error($str, $file, $line)
    {
    die("Fatal error:<font color=#FF0000>$str</font> (<font color=#0000FF>$file</font> ".
    "on line <font color=#FF0000>$line</font>)<br>\n");
    } /* Connect to the Mysql Server */
    function connect()
    {
    $host = $this->_host;
    $link = mysql_connect( $host, $this->_user, $this->_pass );
    $this->debug("Host = $host, user = {$this->_user}, pass = {$this->_pass}",
      __FILE__, __LINE__);
    if (!$link) 
    {
    // mysql connection error
    $this->error(mysql_error(), __FILE__, __LINE__);
    } $this->debug("db = {$this->_db}", __FILE__, __LINE__);
    $db_selected = mysql_select_db($this->_db, $link);
    if (!$db_selected)
    {
    $this->error(mysql_error(), __FILE__, __LINE__);
    }
    return $link;
    } /*
    * excute sql query
    */
    function execute($query)
    {
    $this->debug("SQL = $query", __FILE__, __LINE__);
    $link = $this->connect();
    if ($link)
    {
    $res = mysql_query($query, $link);
    mysql_close($link);
    } else {
    $this->error(mysql_error(), __FILE__, __LINE__);
    } if (!$res)
    {
    $this->error(mysql_error(), __FILE__, __LINE__);
    } else {
    return $res;
    }
    } /*
    * get data set function
    */
    function getset($query)
    {
    $res = $this->execute($query);
    if ($res)
    {
    $row = mysql_fetch_array($res, MYSQL_ASSOC);
    if (!$row) 
    {
    $this->debug("empty set", __FILE__, __LINE__);
    }
    $i = 0;
    while ($row)
    {
    $this->debug($row, __FILE__, __LINE__);
    for ($n = 0; $n < mysql_num_fields($res); $n++)
    {
    $name = mysql_field_name($res, $n);
    //$this->debug("name=$name", __FILE__, __LINE__);
    $rowset[$i][$n] = $row["$name"];
    $rowset[$i]["$name"] = $row["$name"];
    }
    $row = mysql_fetch_array($res, MYSQL_ASSOC);
    $i ++;
    }
    }
    $this->debug("Get <b>$i</b> records", __FILE__, __LINE__);
    $this->debug($rowset, __FILE__, __LINE__); return $rowset;
    } /**/
    }
      

  3.   

    除了next_record()
    还可以用num_rows()来判断
    很灵活的
      

  4.   

    $my_db = new DB_Sql();
      $my_db->connect($db_table,$db_host,$db_user,$db_psw);
      $q = "SELECT * FROM `guestbook` ";
      $my_db->query($q);
      if($my_db->num_rows()>0){
        echo "no record";
      }else{
        while($my_db->next_record()){
           .......
           }
      }根本就不用去看完整个文件,一般只用到:
    (1)   query($query_string) : 執行 SQL 指令(2)   next_record() : 將指標移動到下一筆資料 , 如果傳回值為 false , 代表指標已經到結尾了 (3)   num_rows(), nf() : 兩個指令相同 , 傳回這次的 SQL 抓回有幾筆資料(4)   affected_rows() : 傳回因為 INSERT , UPDATE 或 DELTE 影響有幾筆資料(5)   num_fields() : 傳回這次 SQL 指令抓回的欄位數(6)   f($field) : 傳回欄位名稱為 $field 的資料(7)   seek($pos) : 將資料指標移動 , 類似檔案處理的 seek()(8)   link_id() : 傳回與資料庫連接的代碼
      

  5.   

    哦 不好意思,代码写错,应该这样:
    $my_db = new DB_Sql();
      $my_db->connect($db_table,$db_host,$db_user,$db_psw);
      $q = "SELECT * FROM `guestbook` ";
      $my_db->query($q);
      if($my_db->num_rows()<1){
        echo "no record";
      }else{
        while($my_db->next_record()){
           .......
           }
      }
      

  6.   

    phplib听说模板好用,
    到于DB的,我喜欢用pear!