I seem to be having trouble getting mysqli to return a result from my query. My code is:
$db_conn = get_database(); //function returns a static mysqli object reference
if($result = $db_conn->query("SELECT city
FROM state
WHERE name='CA' ")) {
$row = $result->fetch_object();
$city= $row->city;
$result->close();
} else {
echo $db_conn->error;
}
When I echo the contents of the city variable, it contains nothing.
get_database()
to make sure the proper database is selected state
in your where clause is the same as your table name, state
. Change that to name
instead if you can.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.