Skip to content

Instantly share code, notes, and snippets.

@anta40
Created December 25, 2019 01:58
Show Gist options
  • Save anta40/1db829be5bb299d8c1f745dcc5fc9c28 to your computer and use it in GitHub Desktop.
Save anta40/1db829be5bb299d8c1f745dcc5fc9c28 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL);
$db = new mysqli("localhost","wpdev2019","test2019","wpblog1");
if ($db->connect_errno) {
echo "Failed to connect to MySQL: " . $db-> connect_error;
exit();
}
else {
$myArray = array();
if ($result = $db->query("SELECT ID, post_title, post_name, guid, post_content, post_date from wpkk_posts")) {
$tempArray = array();
while ($row = $result->fetch_object()) {
$tempArray = $row;
array_push($myArray, $tempArray);
}
echo json_encode($myArray);
}
$result->close();
$mysqli->close();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment