You are here: Re: faster way to get from SQL database into array « PHP Programming Language « IT news, forums, messages
Re: faster way to get from SQL database into array

Posted by Erwin Moller on 12/12/06 09:25

Cleverbum@hotmail.com wrote:

>
> Toby Inkster wrote:
>> Rik wrote:
>>
>> > Indeed, or possibly check it first:
>> > $searchstring = md5(//something);
>> > $result = mysql_query("SELECT `textmd5` FROM `logs_full` WHERE
>> > `textmd5` = '{$searchstring}'");
>> > if(mysql_num_rows($result) < 1){
>> > //not in table logic..
>> > } else {
>> > //is in table logic..
>> > }
>>
>> As the OP said, he needs to check "hundreds of thousands" of md5 strings
>> -- using an SQL call for each one will slow him down.
>
> Hit the nail on the head.

Sorry to be rude, but I think you both missed the nail.
You have a certain value that you transform to a md5 and check if it is your
db allready, right?
PHP can do that md5.

After that you simply need to find that value in the table, like:
$mymd5= md5("whatever");
$SQL = "SELECT md5text FROM logs_full WHERE (md5text='".$mymd5."');"

You do not have to make hundreds of thousands of queries, or hundreds of
thousands md5-calculations.
You only feed this query once and sees if it returns any results.

Am I missing something completely here?

Regards,
Erwin Moller

>
>>
>> My advice would be to keep doing roughly what you're already doing, but
>> speed up your array search.
>>
>> To speed up your search, make sure your array is sorted in alphabetical
>> order. You can do this using your initial SQL query:
>>
>> SELECT textmd5 FROM logs_full ORDER BY textmd5;
>>
>> (Note: the query will speed up by specifying the exact column you need to
>> select; not '*'.)
>>
>> You can then use a binary search function[1] instead of in_array() to
>> check that a value exists in your array.
>>
>> ____
>> 1. Such as...
>> http://www.rci.rutgers.edu/~jfulton/binary_search/binary_search.inc
>>
>> --
>> Toby A Inkster BSc (Hons) ARCS
>> Contact Me ~ http://tobyinkster.co.uk/contact
>
> Thanks for the binary search idea I've done some timing and the
> in_array seems to be taking a lot longer than I originally thought it
> would.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация