php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13287 MySQL, PHP and a random problem
Submitted: 2001-09-13 12:31 UTC Modified: 2001-09-14 04:55 UTC
From: alberty at neptunlabs dot de Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0CVS-2001-09-13 OS: i686-pc-linux-gnu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alberty at neptunlabs dot de
New email:
PHP Version: OS:

 

 [2001-09-13 12:31 UTC] alberty at neptunlabs dot de
Hi,

i have found a mystic behavior with
MySQL and PHP.

The follow code describes a problem which i have
only observe in the combination between PHP and MySQL.

i have test it with PHP (406,407dev,408dev) and
MySQL (3.23.39-3.23.42) under suse-linux.

okay, lets go to the problem.

First make a simple table like:

// SQL-Dump
CREATE TABLE footest (
  ID int(10) unsigned NOT NULL default '0',
  KEY ID (ID)
) TYPE=MyISAM;



then push many rows in the table with increasing numbers!

<?php
for ($i=1;$i<=60000;$i++){
	mysql_query("insert into footest (ID) values($i)");
}
?>

okay, and now the miracle comes with this script:

<?php
$result=mysql_query("select ID from footest order by rand() limit 8");
if ($result!=false) while ($tmp=mysql_fetch_assoc($result)){
	echo $tmp['ID']."<br>";
}
else echo mysql_error();
?>

i have attached 5 series from the little code:

Call 1: 52839,36271, 2555,42892,32471,13967,52990,27917
Call 2: 52823,36255, 2539,42876,32455,13951,52974,27901
Call 3: 52775,36207, 2491,42828,32407,13903,52926,27853
Call 4: 52751,36183, 2467,42804,32383,13879,52902,27829
Call 5: 52735,36167, 2451,42788,32367,13863,52886,27813

you see the problem ? No, okay make the same test under
the mysql console. 

Type:
"select ID from footest order by rand() limit 8;"


and mysql results really random rows. strange problem ;-)

i hope some developer have an idea, where the problem is, but
perhaps it is a mysql problem.

Regards,

-- 
Steve

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-13 13:48 UTC] hholzgra@php.net
i guess it's timing-related (and definetly on the MySQL side)

what happens if you call

mysql ... -e "select ID from footest order by rand() limit 8;"

from command line several times instead of typing the query into the same client multiple times?

my first guess would be that you get similar not-so-random results as the RAND() result seems to be related to MySQL client runtime somehow ...
 [2001-09-14 04:36 UTC] alberty at neptunlabs dot de
Yes, with
mysql -e "select ID from footest order by rand() limit 8;"

the same problem.

okay, i post it to the mysql dev. forum.

Regards,

-- 
Steve


 [2001-09-14 04:55 UTC] derick@php.net
Not a bug in PHP, but in MySQl. Closing
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 15:01:29 2024 UTC