Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Sample query
- // GET /query.php?query=SELECT * FROM database_name
- // Variables
- // Connect to Database
- $username = "database_user";
- $password = "user_password";
- $servername = "localhost"; // If the file resides on the same server as the mySQL server then "localhost"
- $dbname = "database_name";
- $sql = $_GET['query'];
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Query and Result
- $result = mysqli_query($conn, $sql) or die("Error in Selecting " . mysqli_error($conn));
- //create an array
- $emparray = array();
- while($row =mysqli_fetch_assoc($result))
- {
- $emparray[] = $row;
- }
- echo json_encode($emparray);
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement