2011-02-16 64 views
0

我試圖做在MySQL select * from my_table,它總是後2000行左右退出。我有大約10,000行。這是一個MySQL錯誤?SELECT *不起作用

編輯:我使用這個類來查詢。 http連接是否超時?

<?php 
    /** 
    * <b>Database Connection</b> class. 
    * @author Php Object Generator 
    * @version POG 2.6.3/PHP4 
    * @see http://www.phpobjectgenerator.com/ 
    * @copyright Free for personal & commercial use. (Offered under the BSD license) 
    */ 
Class DatabaseConnection 
{ 
var $connection; 
var $databaseName; 
var $result; 

// ------------------------------------------------------------- 
function DatabaseConnection() 
{ 
    $this->databaseName = $GLOBALS['configuration']['db']; 
    $serverName = $GLOBALS['configuration']['host']; 
    $databaseUser = $GLOBALS['configuration']['user']; 
    $databasePassword = $GLOBALS['configuration']['pass']; 
    $databasePort = $GLOBALS['configuration']['port']; 

    $this->connection = mysql_connect ($serverName.":".$databasePort, $databaseUser, $databasePassword) or die ('I cannot connect to the database.'); 
    mysql_select_db ($this->databaseName) or die ('I cannot find the specified database "'.$this->databaseName.'". Please edit configuration.php'); 
} 


// ------------------------------------------------------------- 
function Close() 
{ 
    mysql_close($this->connection); 
} 

// ------------------------------------------------------------- 
function GetConnection() { 
    return $this->connection; 
} 

// ------------------------------------------------------------- 
function Query($query) 
{ 
    $this->result = mysql_query($query,$this->connection); 
    return $this->result; 
} 

// ------------------------------------------------------------- 
function Rows() 
{ 
    if ($this->result != false) 
    { 
     return mysql_num_rows($this->result); 
    } 
    return null; 
} 

// ------------------------------------------------------------- 
function AffectedRows() 
{ 
    return mysql_affected_rows(); 
} 

// ------------------------------------------------------------- 
function Result($row,$name) 
{ 
    if ($this->Rows() > 0) 
    { 
     return mysql_result($this->result, $row, $name); 
    } 
    return null; 
} 


// ------------------------------------------------------------- 
function InsertOrUpdate($query) 
{ 
    $this->result = mysql_query($query,$this->connection); 
    return ($this->AffectedRows() > 0); 
} 

/** 
* This function will always try to encode $text to base64, except when $text is a number. This allows us to Escape all data before they're inserted in the database, regardless of attribute type. 
* @param string $text 
* @return string encoded to base64 
*/ 
function Escape($text) 
{ 
    if ($GLOBALS['configuration']['db_encoding'] && !is_numeric($text)) 
    { 
     return base64_encode($text); 
    } 
    return mysql_escape_string($text); 
} 

// ------------------------------------------------------------- 
function Unescape($text) 
{ 
    if ($GLOBALS['configuration']['db_encoding'] && !is_numeric($text)) 
    { 
     return base64_decode($text); 
    } 
    return stripcslashes($text); 
} 

// ------------------------------------------------------------- 
function GetCurrentId() 
{ 
    return intval(mysql_insert_id($this->connection)); 
} 
    } 
    ?> 
+0

大多數情況下並非如此。請詳細說明你如何處理結果集?在什麼情況下會發生?等等。 – 2011-02-16 06:05:49

+4

東西告訴我「選擇」沒有損壞。 – 2011-02-16 06:06:12

回答

1

您是否嘗試過「限制」語句?我認爲這可能是默認限制。

4

解決的第一件事是從任何數據庫管理應用程序(phpMyAdmin的,等等)"SELECT * FROM tbl"。該應用程序應該爲您提供計時信息,以查看查詢需要多長時間。通常,只有10,000條記錄的SELECT ALL應該只需幾ms。

接下來的事情是嘗試"SELECT * FROM tbl"從一個空白的PHP腳本使用直接mysql_x函數 - 沒有包裝在其他功能或類。只需一個小腳本即可獲取循環中的所有行並輸出一些增量計數。

接下來的事情是不使用你的Result($row,$name)方法。甚至PHP suggests not using mysql_result() on large result sets。相反,使用mysql_fetch()或類似的函數從記錄中提取一個數組,然後遍歷它。

此外,仔細檢查你的服務器和PHP錯誤日誌,並確保PHP錯誤報告是滿的。您可能會看到PHP超時錯誤或內存限制錯誤。

0

這是不可能知道沒有看到你實際上是如何獲取和使用效果。我的猜測是你超出了PHP內存限制,可能是因爲試圖將數千行結果放入單個數組中。嘗試單獨穿過它們,例如:

while ($row = mysql_fetch_assoc()) { 
    // do something 
}