Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db.php:
- --------
- --------
- <?php
- $host = "localhost";
- $user = "root";
- $pass = "";
- $db = "test";
- $connect = mysqli_connect( $host, $user, $pass, $db );
- if ( !$connect ) {
- mysqli_error( $connect );
- }
- ?>
- data_select.php:
- ---------------
- ---------------
- <?php
- include 'db.php';
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>select page</title>
- </head>
- <body>
- <?php
- $result = mysqli_query( $connect , $selectQuery ); //read operation from db
- if ( $result ) {
- if ( mysqli_num_rows($result) > 0 ) {
- while ( $row = mysqli_fetch_assoc($result) ) {
- $output[] = $row;
- }
- }
- $finalOutput = json_encode($output); //convert the data in json format from mysql;
- $filename = "data.json"; //the json file which is previously created;
- file_put_contents( $filename, $finalOutput); // store json data in json file;
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement