select * from table不起作用

时间:2011-02-16 06:03:56

标签: php mysql database

我正在尝试在mysql中执行select * from my_table,它总是在2000行左右后退出。我有大约10,000行。这是一个mysql错误吗?

编辑:我正在使用此类进行查询。这是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));
}
   }
   ?>

3 个答案:

答案 0 :(得分:4)

排除故障的第一件事是来自任何数据库管理应用程序(phpmyadmin等)的"SELECT * FROM tbl"。该应用程序应该为您提供计时信息,以查看查询所需的时间。通常,只有一个SELECT ALL 10,000个记录应该只需几毫秒。

接下来是仅使用直接"SELECT * FROM tbl"函数的空白PHP脚本尝试mysql_x - 不包含其他函数或类。只是一个小脚本,用于获取循环中的所有行并输出一些增量计数。

接下来就是不要使用Result($row,$name)方法。甚至是PHP suggests not using mysql_result() on large result sets。相反,使用mysql_fetch()或类似的函数从记录中提取数组,然后迭代它。

此外,请仔细检查您的服务器和PHP错误日志,并确保PHP错误报告已完整。您可能会看到PHP超时错误或内存限制错误。

答案 1 :(得分:1)

您是否尝试过“限制”声明?我认为那可能是默认限制。

答案 2 :(得分:0)

如果不了解实际获取和使用结果的方式,就无法知道。我的猜测是你超过了PHP内存限制,可能是试图将数千行结果放入一个数组中。尝试单独踏入,例如:

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