Here is the process of logging in to MySQL on Linux, creating a database, and creating a table.
yin@yin-ubuntu10:~$ Mysql-u Root-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 360
Server version:5.1.41-3ubuntu12.1 (Ubuntu)
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
mysql> CREATE DATABASE UseCase;
Query OK, 1 row Affected (0.00 sec)
mysql> use UseCase;
Database changed
Mysql> CREATE TABLE User (UserName varchar primary key,password varchar) not null,createtime timestamp default CU Rrent_timestamp);
Query OK, 0 rows affected (0.01 sec) Create a page below to complete the new user's page. The first is a simple form:
Copy CodeThe code is as follows:
PHP uses the $_post array to get the data from the form submitted via the Post method. In the PHP program, we first want to determine that there is a OK field, so that the page is the first access, or the user click OK after the submission, and then determine whether the two password input is unified. You can then get the user name and password to insert into the database. PHP connection MySQL database can generally be used with MySQL extension or mysqli extension, mysqli extension compared to a new point, here we use this way. Mysqli may need to be installed in the configuration, but in my environment it is loaded by default. The MYSQLI extended operations database is generally divided into the following steps: Construct mysqli object, construct statement, bind parameter, execute, close. The code is as follows:
Copy CodeThe code is as follows:
$match =true;
if (Isset ($_post["OK"])) {
$pwd =$_post["Password"];
$pwdConfirm =$_post["ConfirmPassword"];
$match = ($pwd = = $pwdConfirm);
$conn =new mysqli ("localhost", "root", "123", "usecase");
if (Mysqli_connect_errno ()) {
printf ("Connect failed:%s\n", Mysqli_connect_error ());
Exit ();
}
$query = "INSERT into User (Username,password) VALUES (?,?)";
$stmt = $conn->stmt_init ();
$stmt->prepare ($query);
$stmt->bind_param (' SS ', $name, $pwd);
$name =$_post["UserName"];
$pwd =$_post["Password"];
$stmt->execute ();
if ($stmt->errno==0) {
$success =true;
}else {
$success =false;
}
$stmt->close ();
$conn->close ();
}
?>
Where the Bind_param method requires a little explanation, the first parameter means the parameter type. Each character corresponds to a parameter, s represents a string, I represents an integer, D represents a floating-point number, and B represents a blob. Finally, add a little hint to this page:
Copy CodeThe code is as follows:
if (! $match) {?>
Password and Confirm Password must match.
}
?>
if (Isset ($success)) {
if ($success) {
Echo '
User Created successfully! ';
}elseif ($sucess ==false) {
Echo '
User Name existed. ';
}
}
?>
Next, we write a user list page.
Copy the Code code as follows:
| User Name |
Createtime |
Action |
Include ' conn.php '; $query = "SELECT * from User;"; $res = $mysql->query ($query); while ($row = $res->fetch_array ()) {?>
|
|
">edit
">delete
|
} $res->close (); $mysql->close ();?>
http://www.bkjia.com/PHPjc/322815.html www.bkjia.com true http://www.bkjia.com/PHPjc/322815.html techarticle here is the process of logging in to MySQL on Linux, creating a database, and creating a table. yin@yin-ubuntu10:~$ mysql-u root-p Enter password:welcome to the MySQL monitor. Commands End With; or \ ...