-5

I don't know what went wrong, but it doesn't work. It doesn't print out the result. I tried so many solutions for the query but. Maybe someone can help me.

<?php
$hostname = "localhost";
$username = "root";
$password = "";
$databaseName = "dbapp";
$db = mysqli_connect($hostname, $username, $password, $databaseName);
if(!$db) {
exit("Connection failed: ".mysqli_connect_error());
}
$query = "SELECT id FROM datas";

$result = mysqli_query($db, $query);
print($result);
?>
Paul Spiegel
  • 30,925
  • 5
  • 44
  • 53
Chris S.
  • 1
  • 2

2 Answers2

0

You cannot convert the array to string. You must use print_r() in order to print out arrays, so modify this line of code:

print($result);

into

print_r($result);

And to get fetched rows from the database, you have to loop over the result as the following:

while ($row = $result->fetch_assoc()) {
print_r($row); # You can get element from $row as the following $row['id']
}
ndrwnaguib
  • 5,623
  • 3
  • 28
  • 51
0

You make the query but you didn't fetch the data from database yet.

$rows = mysqli_fetch_assoc($result);
var_dump($rows);
samehanwar
  • 3,280
  • 2
  • 23
  • 26