Advertisement
GWibisono

step 1 - bikin text json..

Nov 1st, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2. $database="test";
  3.  
  4. $user = 'root';
  5. $password = '';
  6. $dsn = 'mysql:dbname='.$database.';host=localhost';
  7.  
  8. try {
  9.     $conn = new PDO($dsn, $user, $password);
  10. } catch (PDOException $e) {
  11.     echo 'Connection failed: ' . $e->getMessage();
  12. }
  13.  
  14. $sql="SHOW  FULL  TABLES from $database";
  15. foreach ($conn->query($sql) as $row) {
  16. //print_r($row);
  17.     $table=$row[0];
  18.     $ar=array();
  19.     $sql="select * from $table";
  20.     $sth = $conn->prepare($sql);
  21.     $sth->execute();
  22.     while( $result = $sth->fetch(PDO::FETCH_ASSOC))
  23.     {
  24.         $ar[]=$result;
  25.     }
  26.     $json=json_encode($ar);
  27.      
  28.     $fp = fopen('data/'.$table.".json", 'w');
  29.     fwrite($fp, $json);
  30.     fclose($fp);
  31.     echo "<br> sudah menulis $table";
  32.    
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement