-1

Hello i have one direcory who contain 1000 (.sql) files, am trying to make php script to pull all that files in sql.

This look like this etc..

2013_07_17_00_world_version.sql 2013_07_17_01_world_conditions.sql 2013_07_17_02_world_gossip.sql 2013_07_17_03_world_gossip.sql 2013_07_17_04_world_spell_script_names.sql 2013_07_18_00_world_conditions.sql 2013_07_18_01_world_koralon.sql 2013_07_18_02_world_spell_script_names.sql 2013_07_18_02_world_the_flesh_giant_slayer.sql 2013_07_18_03_world_equipment.sql 2013_07_19_00_world_misc.sql 2013_07_20_00_world_gameobject.sql 2013_07_20_01_world_misc.sql 2013_07_23_00_world_misc.sql 2013_07_23_02_world_creature_template.sql 2013_07_24_00_world_spell_script_names.sql 2013_07_24_01_world_spell_ranks_335.sql 2013_07_24_02_world_trinity_strings.sql 2013_07_24_03_world_spell_proc_event_335.sql 2013_07_25_00_world_spell_script_names.sql

My strategy is first to take file name and put that name in query but i do somthing wrong. Any1 have idea or softwere how can pull multy..

my code is :

<?php

$path = 'updates/world';
$user = 'root';
$pass = 'socvbe';
$host = 'localhost';
$base = 'world';

mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($base) or die(mysql_error());


if ($handle = opendir($path)) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
           //echo "$entry\n<br>";
            mysql_query($entry) or die('error in query');

        }
    }
    closedir($handle);
}
?>
Ivan
  • 5,139
  • 11
  • 53
  • 86

1 Answers1

0

php isn't smart enough to know that you want to read the contents of your .sql files and use that contents as the queries to mysql. Currently you are sending filenames to mysql_query but it expects an sql query. First you need to get the queries from the file by either opening it with fopen and reading with fread or by using the file_get_contents function.

See here to use file_get_contents

See here to use fopen/fread

elitechief21
  • 2,964
  • 1
  • 17
  • 15