dimanche 30 septembre 2018

How to get data from MySQL with PHP

Hello all I am tryin to build IOS app and I need to get data my MySQL database. I do not know php. I found a tutorial https://codewithchris.com/iphone-app-connect-to-mysql-database/ In section 3 where we create PHP service I copy it and edit for mine information. PHP code is like that

<?php

//create connection
$con=mysqli_connect("localhost","myuserid","mypassword","i4142489_wp1");

// Check connection
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// This SQL statement selects ALL from the table 'Locations'
$sql = "SELECT * FROM treelibrary";

// Check if there are results
if ($result = mysqli_query($con, $sql))
{
    // If so, then create a results array and a temporary one
    // to hold the data
    $resultArray = array();
    $tempArray = array();

// Loop through each row in the result set
while($row = $result->fetch_object())
{
    // Add each row into our results array
    $tempArray = $row;
    array_push($resultArray, $tempArray);
}

// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}

// Close connections
mysqli_close($con);

?>

I load it the my server and nothings pops up just the blank page... Is there any reason or where is my mistake. Thanks for helps. Have a nice day.




Aucun commentaire:

Enregistrer un commentaire