Storing data from php script

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gavox
Forum Newbie
Posts: 2
Joined: Sat May 24, 2008 7:12 pm

Storing data from php script

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Storing data from php script

Post by Christopher »

Maybe post a code example so we can see what you are trying to do?
(#10850)
gavox
Forum Newbie
Posts: 2
Joined: Sat May 24, 2008 7:12 pm

Re: Storing data from php script

Post 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.
Post Reply