Page 1 of 1

Storing data from php script

Posted: Sat May 24, 2008 7:19 pm
by gavox
Hi All,

I have written a script to generate strings. I was wondering if it was possible to store the strings into a mysql database without having to insert each row individually, as this would require thousands of queries, which is not ideal.... My first thought was using arrays, and then storing the array to a database. After doing some research on this however, it would seem that it is difficult to store an array into a database such that the data is searchable afterwards, unless of course one used a loop to retrieve each element from the array, and then store it, but that then requires thousands of queries again.... :banghead:

Any help would be greatly appreciated.

Re: Storing data from php script

Posted: Sat May 24, 2008 10:57 pm
by Christopher
Maybe post a code example so we can see what you are trying to do?

Re: Storing data from php script

Posted: Sat May 24, 2008 11:47 pm
by gavox
Sorry, I should have been a little more specific. I have a function called 'stringy', which is fed a number. Based on that number it returns a string. For testing purposes I am just generating a set of 10 strings.....

Code: Select all

$counter = 0;
while $counter < 10
{
    $number = rand(0,1000);
    $temp = Stringy($number);
    echo $temp;
    echo '<br>';
    $templist[$counter] = array('id' => $number, 'string' => $temp);
    $counter = $counter + 1;
} 
Basically what I want to do is take that array and insert its data into a mysql database. Just not sure how to go about it. The only thing I have tried with any success is having an insert-into query on each pass of the while loop. Not ideal me thinks....
I have done some research and the only solution I came across was serialize / unserialize. However this leaves the data in the database unsearchable. Was wondering if anyone had come across any other methods.

BTW the array structure is the same as the table structure, i.e. a two column table.

I hope all of that makes some sense....
Cheers, Gavin.