Php is used to obtain data in the database. php is used to obtain data in the database.
Let's just talk about the code.
<? Php header ("Content-type: text/html; charset = UTF-8"); // character encoding settings $ servername = "localhost"; $ username = "root "; $ password = "root"; $ dbname = "web"; // create a connection $ con = mysqli_connect ($ servername, $ username, $ password, $ dbname ); // check the connection $ SQL = "SELECT * FROM users"; $ result = mysqli_query ($ con, $ SQL); if (! $ Result) {printf ("Error: % s \ n", mysqli_error ($ con); exit () ;}$ jarr = array (); while ($ rows = mysqli_fetch_array ($ result, MYSQL_ASSOC) {$ count = count ($ rows); // it cannot be in a loop statement, because the length of each row array is reduced by for ($ I = 0; $ I <$ count; $ I ++) {unset ($ rows [$ I]); // Delete redundant data} array_push ($ jarr, $ rows);} echo $ str = json_encode ($ jarr); // encode the array in json format?>
This is converted to json format after obtaining
The above php method for getting data from the database is to share all the content with you, hoping to give you a reference, and hope you can support the house of helpers.