use the mysql functions. - see www.php.net/mysql.
if you're on windows (i assume, since you're on this list), mysql functions
are built in.

in a nut shell :



> $row = 1;
> $fp = fopen ("test.txt","r");

$con = mysql_connect(-mysql_server_ip-, -username-, -password-);
$con = mysql_select_db (-databasename-)

> while ($data = fgetcsv ($fp, 1000, "\t")) {
>     $num = count ($data);
>     $row++;
>     for ($c=0; $c<$num; $c++) {
>         print $data[$c] . "<br>";
>     }
mysql_query("INSERT into tablename SET('blah', $data);

> }
> fclose ($fp);
mysql_close($con);
>
> ?>



Siggy


----- Original Message -----
From: "Ben Cairns" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, February 03, 2001 6:00 AM
Subject: [PHP-WIN] Reading CSV data into a database


> I have this script:
> <?
>
> $row = 1;
> $fp = fopen ("test.txt","r");
> while ($data = fgetcsv ($fp, 1000, "\t")) {
>     $num = count ($data);
>     $row++;
>     for ($c=0; $c<$num; $c++) {
>         print $data[$c] . "<br>";
>     }
> }
> fclose ($fp);
>
> ?>
> It reads a csv file (actually its tab seperated) into an array called
$data.
>
> When I call this in my browser, this is fine. But what I need to do is to
> put this information into a MySQL database...
>
> The file contains these fields:
> region
> event_type
> event_date
> title
> info
> times
> venue
> price
> event_id (this is auto_incrementing)
>
> How do I read this file into the database?
>
> Any help appreciated, as I have RTFM but I still no idea......
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to