Mysql php cursor

I need to create a MySQL cursor to keep track of which row number I’m currently finding when I look at the “huge” table (millions of wishes).

example database table:

CREATE TABLE  test (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
someText TEenter code hereXT NOT NULL
) ;

if this table has 1,000,000 records; I execute the following query:

select * from test where id >= 50;

And then I process the data as needed in my php script (with a limit of 1 min). How do I track to which row I went through the test pattern?

+3
source share
1 answer
// use a PHP session to store the id (could also use cookies...)
session_start();

// your 1 minute timeout
set_time_limit(60);

// query your results (may even put a known-out-of-reach limit on the
// query just to make sure you're not always pulling all the entries every
// reload (that would each up your timeout alone, depending)
$lastID = 0; // lowest possible ID value (e.g. MIN(id) )
if (session_is_registered('last_select_id'))
{
  $lastID =(int)$_SESSION['last_select_id'];
}
else
{
  session_register('last_select_id');
  $_SESSION['last_select_id'] = $lastID;
}
$dbResult = mysql_query("SELECT * FROM test WHERE id>{$lastID} ORDER BY id"/* LIMIT 10000 */);
if ($dbResult)
{
  while (($row = mysql_fetch_row($dbResult)) !== false)
  {
    // perform processing

    // mark as last processed (depending how many steps,
    // you may decide to move this from end to somewhere
    // else, just sh*t luck where your timeout occurs)
    $_SESSION['last_select_id'] = $row['id'];
  }
}

// it reached the end, save to assume we can remove the session variable
session_unregister('last_select_id');

I can only by what you tell me, although I feel that it should be throttled initially , and not just wait for PHP to spit out a timeout.

EDIT , , ALTER "" , .

EDIT2 , . / . , , ($ lastID , 1 ).

0

Source: https://habr.com/ru/post/1784864/


All Articles