Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.ajax({
- type: "GET",
- url: "connect/database.php",
- dataType: "json",
- success: function(response){
- alert(response);
- }
- });
- <?php
- $servername = "localhost";
- $username = "the_username";
- $password = "the_password";
- $dbname = "the_db";
- // create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $array_result = array();
- $sql = mysqli_query("select * from table where user = 'bobo'");
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- $array_result[] = $row;
- }
- } else {
- echo "0 results";
- }
- $conn->close();
- print json_encode($array_result)
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement