Hi Gavin.

Maybe this help You :)

file: import.php
<?php

$my_host       = "localhost";
$my_database   = "xxxxxxx";
$my_user       = "xxxxxxx";
$my_password  = "xxxxxxx";

if (!$db) {
   $db=mysql_pconnect($my_host, $my_user, $my_password);
   if(!$db){
  echo "FATAL:Couldn't connect to db.<br>";
    exit;
   }
   mysql_select_db($my_database, $db);
}

$dh = dir('/home/httpd/html');
while ($entry = $dh->read()) {
  if (preg_match('/\.sql$/i', $entry)) {
    $matching[] = $entry;
  }
}

for ($j=0; $j<count($matching); $j++) {
  $line = file("/home/httpd/html/matching[$j]");
  $nr = 0;
  for ($i=0; $i<count($line); $i++) {
    $line[$i] = trim( $line[$i] );
    # for browser timeout problem handling
    if ($nr > 100) {
      echo "#";
      $nr = 0;
    } else{
      $nr = $nr + 1;
    }
    $result = mysql_query($line[$i], $db);
    # need add error handling
  }
}
echo "Ready\n";
mysql_close($db);


file: file1.sql
INSERT INTO firma VALUES ( 'XXXXX', 'XXXX', '', '', '', '', '*');
INSERT INTO firma VALUES ( 'YYYYY', 'YYYY', 'YYYY', 'YYYY', '222', '', '*');

file: file2.sql
INSERT INTO firma VALUES ( 'XXXXX', 'XXXX', '', '', '', '', '*');
INSERT INTO firma VALUES ( 'YYYYY', 'YYYY', 'YYYY', 'YYYY', '222', '', '*');

and now call import script:
http://www.wwwwww.com/import.php

Indrek Järv
[EMAIL PROTECTED]

Gavin Tong wrote:

> Hi, I've been trying to get this script to read a directory and then pass the 
>information into a Mysql table.  I can open the directory and print it's contents, or 
>I can get other information from variables passed to the mysql table, but I can't 
>seem to do both.  If you have any idea what I've done wrong or have an idea where I 
>can read more about this problem your thoughts will be greatly appreciated.
> Sincerely,
> Gavin Tong
>
> <?php
> $handle=opendir('.');
> while (false!==($file = readdir($handle))) {
>     if ($file != "." && $file != "..") {
>         echo "$file\n";
>     }
> }
> closedir($handle);
> $db = mysql_connect("local host", "person", "pasword");
> mysql_select_db("photos",$db);
> $result = mysql_query("insert into template (name) values ('$file')",$db);
> ?>


-- 
PHP Database 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