简体   繁体   中英

Mysqli Query is not returning any result

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.

  1. Check get_database() to make sure the proper database is selected
  2. The column 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM