PHP ?? ??? ???? ?? ?????? ??
??? ???? ?????? ??
?? ??? ?? ??? ??? ????? ???? ????? ??? ????? ? ? ??? ?????. ??? "username"?? ???? ??? "password"???.
?????? ??
??? ??????? ???? ?? ?? mysql ??? ??? ? ????. ? ???? PHP ??? ???? ??????? ?????
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 $servername = "localhost"; $username = "root"; $password = "root"; // 創(chuàng)建連接 $conn = mysqli_connect($servername, $username, $password); mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 // 檢測連接 if (!$conn) { die("連接失敗: " . mysqli_connect_error()); } // 創(chuàng)建數(shù)據(jù)庫 $sql = "CREATE DATABASE login"; if (mysqli_query($conn, $sql)) { echo "數(shù)據(jù)庫創(chuàng)建成功"; } else { echo "數(shù)據(jù)庫創(chuàng)建失敗: " . mysqli_error($conn); } mysqli_close($conn); ?>
?? ??? login??? ??????? ?????. ??????
??? ??? ???
??? ??? ??? user
?? ?? | id???. | ??? ?? | ???? |
?? ?? | INT | VARCHAR | VARCHAR |
?? ?? | 6 | 30 | 30 |
?? ?? | ??? ID | ??? ?? | ???? |
??? ??? ? ?? ?? ??? ??? ????
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "login"; // 創(chuàng)建連接 $conn = mysqli_connect($servername, $username, $password, $dbname); mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 // 檢測連接 if (!$conn) { die("連接失敗: " . mysqli_connect_error()); } // 使用 sql 創(chuàng)建數(shù)據(jù)表 $sql = "CREATE TABLE user ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(30) NOT NULL, password VARCHAR(30) NOT NULL );"; if (mysqli_query($conn, $sql)) { echo "數(shù)據(jù)表 user 創(chuàng)建成功"; } else { echo "創(chuàng)建數(shù)據(jù)表錯誤: " . mysqli_error($conn); } mysqli_close($conn); ?>
? ??? "id", "username" ? "password"? ? ?? ??? ?? "user"?? ??????? ?????.
phpmyadmin? ?? ???
??????? ??? ?? ? ? ????. ?? ??? ?? ???? ???? ????. ??????? ??? ??? HTML ?? ???? ?? ? ????