Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading from a database with PHP

I'm trying to pull some information from a database, and the connection is working, but for some reason it isn't recognizing my query, even though I confirmed the query in the database with SQL and had it "generate PHP code". The echo statement is coming up blank. It's a mySQL database. Thanks for your help.

$query = "SELECT `contact` FROM `contactinfo` WHERE member=\'Henry\'";
$contact = mysqli_query($db,$query);
echo $contact;
like image 599
Henry Avatar asked Aug 13 '26 13:08

Henry


1 Answers

$contact contains MySQL result object you need to fetch data from this to use this in your application.

$query   = "SELECT `contact` FROM `contactinfo` WHERE member = 'Henry'";
$contact = mysqli_query($db, $query);
while ($row = mysqli_fetch_row($contact)) {
  echo $row[0]; // 0 to n indicates the Column(s) Selected in SELECT Query
}
like image 86
GoodSp33d Avatar answered Aug 16 '26 11:08

GoodSp33d