I'm having some trouble fetching some data from a database using MySQLi, I'm not sure what i'm doing wrong, already tried quite a few different ways of calling stuff out of the table and nothing seems to be doing it.
it's been a while since i've coded php, i'm still trying to get my head around the MySQli changes.
Here's what I get when I run my code -
Connected successfully
Could not successfully run query (SELECT * FROM articles) from DB:
here's the code -
<?php
require_once('config.php');
//global $config;
$security_check = 1;
if(!isset($security_check))
{
echo "This is restricted directory";
exit();
}
function viewarticles()
{
global $config;
// Create connection
$conn = new mysqli($config['hostname'], $config['username'], $config['password']);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "Connected successfully";
echo "<br/>";
}
$sql = "SELECT * FROM articles";
$result = $conn->query($sql, MYSQLI_STORE_RESULT);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
while($row = $result->fetch_assoc())
{
echo $result->title;
}
$result->free();
$conn->close();
}
viewarticles();
?>