[PHP] Include file for MySQL insert rows

2002-02-17 Thread Paul Fowler

I am very new at this and am having trouble migrating to php and mysql from
a different system (WebCatalog).

I want to start dumping files to text and let php use them to populate mysql
on the fly as I start migrating.

snip---

$db  = mysql_pconnect(host, user, pass);

$query = insert into catalogwinetmp values
include(testsql);

$result = mysql_query($query);

---end-snip

The contents of testsql look like this

(19, 38080, 'Senejac', 'Haut-Medoc / Cru Bourgeois', '', 12, 1995, 'Bottle -
.75L', 'LN, LE, CI', 135, '/collectors/images/bottles/38080.JPG'),
(20, 38780, 'Yquem', 'Sauternes / Premier Cru Superieur', '', 1, 1927,
'Bottle - .75L', 'TS, LP, CI', 465, '/collectors/images/bottles/38780.JPG');

Just with more lines (1-18).

But I can not get rid of errors in the
$query = insert into catalogwinetmp values
include(testsql);
No matter what quotes and semi-colons I put in testsql or in this script.

If I try to set the contents of the include into a variable as in:

$rowsToAdd = include(testsql);

all I get is the value 1, I guess this is because it is successful.

If I could get a variable to contain the contents of the include I am not
sure if I could use it in the script.

I am not sure if I am even getting warm or if I am on another planet.


1. Any ideas how I can simply make php get a text file into the mysql
database?

2. Is there a way to set a (albeit maybe large) variable with the contents
of an include file?

Sorry to sound like such a php newbie, but I am.

Kind thanks,

Paul


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




Re: [PHP] Include file for MySQL insert rows

2002-02-17 Thread Janet Valade

INCLUDE is not really what you are looking for. INCLUDE is more to read in
files that contain PHP code. If I'm understanding correctly, what you want
to do is to read each line from your file and put each line into a separate
variable. Then, you can create the INSERT statement for each row.

It might go something like this:

$fp = fopen(testsql,r) ;
while ($row = fgets($fp,1024))
{
$query = INSERT INTO catalogwinetmp VALUES $row;
   $result = mysql_query($query);
}

It looks like there might be something at the end of each line that you need
to remove before you construct the query. A comma on the first line and a
semicolon on the second line.

Janet



- Original Message -
From: Paul Fowler [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, February 17, 2002 8:17 PM
Subject: [PHP] Include file for MySQL insert rows


 I am very new at this and am having trouble migrating to php and mysql
from
 a different system (WebCatalog).

 I want to start dumping files to text and let php use them to populate
mysql
 on the fly as I start migrating.

 snip---

 $db  = mysql_pconnect(host, user, pass);

 $query = insert into catalogwinetmp values
 include(testsql);

 $result = mysql_query($query);

 ---end-snip

 The contents of testsql look like this

 (19, 38080, 'Senejac', 'Haut-Medoc / Cru Bourgeois', '', 12, 1995,
'Bottle -
 .75L', 'LN, LE, CI', 135, '/collectors/images/bottles/38080.JPG'),
 (20, 38780, 'Yquem', 'Sauternes / Premier Cru Superieur', '', 1, 1927,
 'Bottle - .75L', 'TS, LP, CI', 465,
'/collectors/images/bottles/38780.JPG');

 Just with more lines (1-18).

 But I can not get rid of errors in the
 $query = insert into catalogwinetmp values
 include(testsql);
 No matter what quotes and semi-colons I put in testsql or in this script.

 If I try to set the contents of the include into a variable as in:

 $rowsToAdd = include(testsql);

 all I get is the value 1, I guess this is because it is successful.

 If I could get a variable to contain the contents of the include I am not
 sure if I could use it in the script.

 I am not sure if I am even getting warm or if I am on another planet.


 1. Any ideas how I can simply make php get a text file into the mysql
 database?

 2. Is there a way to set a (albeit maybe large) variable with the contents
 of an include file?

 Sorry to sound like such a php newbie, but I am.

 Kind thanks,

 Paul


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



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