Advertisement
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();
- }
- $sql="SHOW FULL TABLES from $database";
- foreach ($conn->query($sql) as $row) {
- //print_r($row);
- $table=$row[0];
- $ar=array();
- $sql="select * from $table";
- $sth = $conn->prepare($sql);
- $sth->execute();
- while( $result = $sth->fetch(PDO::FETCH_ASSOC))
- {
- $ar[]=$result;
- }
- $json=json_encode($ar);
- $fp = fopen('data/'.$table.".json", 'w');
- fwrite($fp, $json);
- fclose($fp);
- echo "<br> sudah menulis $table";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement