PHP development and implementation of download count statistics function module (1)
First put the database connection code into the conn.php fileIt is convenient to use require 'conn.php' call.
The require statement is used to insert useful code written in other files into the execution flow
The following is the database file conn.php
Create one that is filelist.php, used to read the data in the mysql data table, and output the data in JSON format to call the front-end html page
First use the require statement to call the conn.php database file, and pass the SQL statement SELECT reads out all the data in the database downloads table
Save the id, filename and other while loop output in the data table into an array $data[], and then save the data in the $data[] array echo is in JSON format, which is convenient for calling the front-end html page.
filelist.php file content is as follows:
$row['id'], 'file' => $row['filename'], 'downloads'=> $row['downloads'] ); } echo json_encode($data); //json_encode—返回一个值的JSON格式 } ?>
mysqli_num_rows() function returns the number of rows in the result set
json_encode—returns the JSON format of a value