Php queries the mysql database and saves the result to an array
This article describes how to query the mysql database in php and save the results to an array. The example shows how to query the database using mysql_fetch_assoc in php. For more information, see
This example describes how php queries mysql Databases and saves the results to arrays. Share it with you for your reference. The specific analysis is as follows:
The mysql_fetch_assoc function is used here.
The mysql_fetch_assoc syntax is as follows:
?
| 1 |
Array mysql_fetch_assoc (resource $ Result_Set) |
The sample code is as follows:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<? Php $ UserName = 'abc '; $ Password = '000000 '; $ DbHandle = mysql_connect ('localhost', $ UserName, $ Password ); If (! $ DbHandle ){ Die 'no database connection cocould be established .'; } $ DBName = 'wdb; If (! Mysql_select_db ($ DBName, $ DbHandle )){ Die 'database cocould not be selected .'; } $ Query = "select isbn, Title, Author FROM articles "; $ Articles = mysql_query ($ Query, $ DbHandle )); While ($ Row = mysql_fetch_assoc ($ articles )){ Echo "ISBN = $ Row ['isbn '] <br/> \ n "; Echo "Title = $ Row ['title'] <br/> \ n "; Echo "Author = $ Row ['author'] <br/> \ n "; } ?> |
I hope this article will help you with php programming.