Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Re: Re: Apache::DBI, DBI, DBD::MySql and MySQL cache?

by perrin (Chancellor)
on Mar 17, 2003 at 21:08 UTC ( [id://243802]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Apache::DBI, DBI, DBD::MySql and MySQL cache?
in thread Apache::DBI, DBI, DBD::MySql and MySQL cache?

The code is really hard to read because you didn't put in CODE tags. However, I don't see anything wrong with that sub. I think this is a MySQL issue after all. Take a look at this coment from the MySQL manual:

As of MySQL 3.23.52, MySQL changed the way RAND() functions, such that you MUST supply a SEED to get an actual random number. If you do not, each new connection will return close to the same number as the previous new connection. An example to test this would be to run the follow command multiple times in a row. mysql -u username -p -e'select rand()' A basic way to seed this would be to run RAND(NOW()).

  • Comment on Re: Re: Re: Re: Apache::DBI, DBI, DBD::MySql and MySQL cache?

Replies are listed 'Best First'.
Re^5: Apache::DBI, DBI, DBD::MySql and MySQL cache?
by Flame (Deacon) on Mar 17, 2003 at 21:34 UTC
    Ok the code tags are an oops, I thought they were there, must have deleted them (there was an older version of the same program already there, and I deleted that and pasted in the new one.)

    Update: Fixed code tags



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Re: Re: Re: Re: Re: Apache::DBI, DBI, DBD::MySql and MySQL cache?
by Flame (Deacon) on Mar 17, 2003 at 21:55 UTC

    Hmm, your quote from the MySQL manual seems to work. Only I'm twisting it a little to use RAND(?) and I pass a Perl-generated rand :) It's still not quite as random as I would like, but it's definately better. As to the console select statement test, sorry but that failed (diff number each time), but with perl passing different rand numbers most of the time, it's interesting at least.

    Modified Code:
    my $sth = $state->{'DBH'}->prepare('SELECT quote,author FROM quotes + ORDER BY RAND(?) LIMIT 1'); $sth->execute(rand(10000)); my $row = $sth->fetchrow_arrayref; $sth->finish;




    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://243802]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-19 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found