PHP development...LOGIN

PHP development to implement download count statistics and create database tables

First create the database test

<?php
// 创建连接
$conn = new mysqli("localhost", "uesename", "password");
// 检测连接
if ($conn->connect_error) 
{    
    die("连接失败: " . $conn->connect_error);} 
    // 创建数据库
    $sql = "CREATE DATABASE test";
        if ($conn->query($sql) === TRUE) 
        {    
        echo "数据库创建成功";
        } else {    
        echo "Error creating database: " . $conn->error;
        }
    $conn->close();
?>

and then create a downloads table to record the file name, the file name saved on the file server and the number of downloads.

The structure is as follows:

<?php
$SQL = "CREATE TABLE IF NOT EXISTS `downloads` ( 
  `id` int(6) unsigned NOT NULL AUTO_INCREMENT, 
  `filename` varchar(50) NOT NULL, 
  `savename` varchar(50) NOT NULL, 
  `downloads` int(10) unsigned NOT NULL DEFAULT '1', 
  PRIMARY KEY (`id`), 
  UNIQUE KEY `filename` (`filename`) 
) ENGINE=MyISAM  DEFAULT CHARSET=utf8; "
?>

id: It is unique, of type int, and selects the primary key.

filename: file name, type is varchar, length is 50.

savename: Downloaded file name, type is varchar, length is 50.

downloads: Number of downloads, type int.

After creating the table, add a few pieces of test data

<?php
$SQL = "INSERT INTO `downloads` (`id`, `filename`, `savename`, `downloads`) VALUES
(1, '下载测试1.zip', '201611.zip', 1),
(2, '我要下载1.jpg', '20160901.jpg', 1),
(3, 'Microsoft Office Word 文档.docx', '20130421098547547.docx', 5),
(4, 'Microsoft Office Excel 工作表.xlsx', '20130421098543323.xlsx', 12);"
?>

This completes the creation of the database table.

In order to ensure the integrity of the test function, you need to create a files folder in the local directory, and place Microsoft Office Word document.docx, Microsoft Office Excel worksheet.xlsx and other files here. folder.

Otherwise, it will prompt that the file does not exist.

Next Section
<?php // 创建连接 $conn = new mysqli("localhost", "uesename", "password"); // 检测连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error);} // 创建数据库 $sql = "CREATE DATABASE test"; if ($conn->query($sql) === TRUE) { echo "数据库创建成功"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?>
submitReset Code
ChapterCourseware