天蓬老师2017-09-15 14:31:20
There is something wrong with your usage~~
The prerequisite for using $mysqli->query() is: you have created the $mysqli object. I wonder if you have created this object in the dbconfigs.php file?
Also, you used mysqli_fetch_array() below. This is a typical process-oriented statement. I really don’t understand how you want to call the data?
If you want to use object-oriented, please use it like this:
$mysqli = new mysqli($host,$userName,$password,$dbName); if ($mysqli->connect_errno){ die('Error Connected'.$mysqli->connect_error; } $result = $mysqli->query('SELECT * FROM table_name'); if ($result && $result->num_rows > 0){ while($row = $result->fetch_array(MYSQLI_ASSOC)){ //输出数据 } $result->free_result(); } $mysqli->close();
If it is process-oriented, please modify the above code:
$conn = mysqli_connect($host,$userName,$password,$dbName); if (mysqli_connect_errno($conn)){ die('Error Connected'.mysqli_connect_error($conn); } $result = mysqli_query('SELECT * FROM table_name'); if ($result && mysqli_num_rows($conn,$result) > 0){ while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){ //输出数据 } mysqli_free($result); } mysqli_close($conn);
Please do not mix object-oriented and process-oriented.
PHP Chinese website has tutorials for these two parts:
http://www.php.cn/course/653.html (MySQLi object-oriented)
http://www.php.cn/course/653 .html (MySQLi is process-oriented)