On 8/11/2011 9:34 AM, Jason Pruim wrote:
>
> Hey Jim,
>
> Would that still hold true with inserting into a database which is the true
> end of it? This is going to be a one time thing I'm doing and I'm trying to
> make it a learning experience as I go since that's what everything should be
> right?
>
Yes, taking one of your other emails, you would do something like this.
<?PHP
$SQL = "SELECT areacode, prefix
FROM Test
WHERE `areacode` = '907'
AND `prefix` = '200'";
$result = mysql_query($SQL);
$values = '';
while( $row = mysql_fetch_assoc($result) ) {
foreach ( range(0, 9999) AS $n ) {
$values .= " VALUES ('".
sprintf('%03d-%03d-%04d', $row['areacode'], $row['prefix'], $n) .
"')";
}
}
echo 'INSERT INTO Test (fullnumber) ' . $values;
?>
You should see...
INSERT INTO Test (fullnumber) VALUES ('907-200-0000') VALUES ('907-200-0001')
VALUES ('907-200-0001') etc...
What this allows you to do is have one long string generated in memory then
inserted into the DB. If you have any type of indexes on this table/column then
it would only require one re-indexing of the table for the single INSERT
statement vs 10000 re-indexes for 10000 separate INSERT statements.
Cuts the DB processing time down a lot.
Also, just so you know, if you place set_time_limit(0); at the top of the
script, it will allow the script to run as long as it needs to.
See: http://php.net/manual/en/function.set-time-limit.php
Jim Lucas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php