Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $database="test";
- $user = 'root';
- $password = '';
- $dsn = 'mysql:dbname='.$database.';host=localhost';
- try {
- $conn = new PDO($dsn, $user, $password);
- } catch (PDOException $e) {
- echo 'Connection failed: ' . $e->getMessage();
- }
- $d = dir("data");
- while (false !== ($entry = $d->read()))
- {
- if($entry!='.'&&$entry!='..')
- {
- //echo $entry."\n<br/>";
- $f=file_get_contents("data/$entry");
- $ar=json_decode($f, TRUE);
- $table=str_replace(".json",'',$entry);
- $table=trim($table);
- foreach($ar as $ar2)
- {
- $data="";$i=1;
- foreach($ar2 as $val)
- {
- if($i!=1)
- {
- $data.=", ";
- }
- $i++;
- $data.="'".addslashes($val)."'";
- }
- $sql="insert into $table values ($data);";
- $sth = $conn->prepare($sql);
- $sth->execute();
- $data='';
- }
- }
- }
- $d->close();
- echo 'done';
Advertisement
Add Comment
Please, Sign In to add comment