Re: Mass MySQL INSERT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 29 November 2004 03:54, Travis Conway wrote:
> I am fairly new to the concept of working wity mysql and php. 

Questions regarding the use of databases with PHP should be posted to the 
php-db list.

> I am looping 
> thru a text file full of county names and attempting to add these to a
> database.

> Now the table exists and if I enter the SQL statement manually against the
> database it works.  The user also has read and write permissions to the
> table and the columns in the table.
>
> Here is my php code:
>  $lines = file("/tmp/new1.txt");
>  foreach ($lines as $line_num => $line) {
>   echo($line . '... ');
>    $link = mysql_connect('naabe', 'naabe', 'xxxxxxxxx')

The connection should be made only once outside of the loop.

>     or die('could not connect: ' . mysql_error());

Using mysql_error() is good, use it more often ...

>     // I use substr to remove the space at the end of every line.
>    $sql = "INSERT INTO countries (country) VALUES ('" .
> substr($line,0,strlen($line)-1) . "')"; echo ($sql . ' ...<br>');
>    mysql_query($sql);

... like here. If your query barfs you'll want to know about it.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
If you see an onion ring -- answer it!
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux