开发者

select * from table does not work

I am trying to do select * from my_table in mysql and it always quits after 2000 rows or so. I have about 10,000 rows. Is this a mysql bug?

EDIT : I am using this class to query. Is it the http connection getting timed out.

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


// ---开发者_JS百科----------------------------------------------------------
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));
}
   }
   ?>


First thing to troubleshoot is "SELECT * FROM tbl" from any db admin application (phpmyadmin, etc). That application should give you timing information to see how long the query takes. Usually, just a SELECT ALL of 10,000 records should take just a few ms.

Next thing is to try "SELECT * FROM tbl" from just a blank PHP script using direct mysql_x functions only - no wrapping in other functions or classes. Just a small script to fetch all rows in a loop and output some incremental count.

Next thing is to not use your Result($row,$name) method. Even PHP suggests not using mysql_result() on large result sets. Instead, use mysql_fetch() or similar function to pull an array from the record, then iterate over that.

Also, check your server and PHP error logs closely and make sure PHP error reporting is on full. You may see a PHP timeout error or a memory limit error.


Have you tried "limit" statements? I think it may be default limit then.


It's impossible to know without seeing how you actually fetch and use the results. My guess is that you're exceeding the PHP memory limit, probably by attempting to put the thousands of rows of results into a single array. Try stepping thru them individually, e.g.:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜