下面是在Linux上登录mysql,创建数据库和创建表的过程。
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(20) primary key,Password varchar(20) not null,CreateTime timestamp default current_timestamp);
Query OK, 0 rows affected (0.01 sec)下面就来建立一个页面来完成新建用户的页面。首先是一个简单的表单:
复制代码 代码如下:
复制代码 代码如下:
$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();
}
?>
复制代码 代码如下:
if(!$match) { ?>
Password and Confirm Password must match.
User Created Successfully!';
}elseif($sucess==false) {
echo '
User Name existed.';
}
}
?>
复制代码 代码如下:
User Name | CreateTime | Action |
---|---|---|
= $row['UserName'] ?> | = date('Y-m-d',strtotime($row['CreateTime']))?> |
Edit Delete |