添加数据库| 数据库名 | 操作 | | —- | —- | | Php07 | 修改 删除 |
Figure : img
Figure : img1.有一个用户提交数据库名的表单文件
Figure : img
Figure : img2.有一个接收用户提交数据并处理的页面 //03.createdatabase.php<?php
//1.接收数据库名
$dbname = isset($_POST[‘dbname’]) ? $_POST[‘dbname’] : ‘’;
//2.验证数据
if($dbname == ‘’){
echo ‘数据库名不能为空!’;
exit;
}
//3.创建数据库
//3.1链接数据库
$link = @mysql_connect(‘localhost’,’root’,’’);
if(!$link){
echo ‘链接数据库失败!’;
exit;
}
//3.1设置编码
mysql_query(‘set names utf8’);
//3.2准备创建数据库SQL语句
$sql = “create database {$dbname} charset=utf8”;
//3.3发送SQL语句
$res = mysql_query($sql);
//3.4判断是否成功
if($res){
echo ‘创建数据库成功!’;
}else{
echo ‘创建数据库失败!’;
}
?>在02.database.php
Figure : img
Figure : img
Figure : img1.通过超链接发生数据库名称到处理页面:02.database.php
Figure : img2.接收数据库名并处理页面:03.dropdatabase.php
Figure : img1.用过超链接传递数据库名到处理页面:02.database.php
Figure : img2.选择字符集和校对集的页面:03.alterdatabase.php<?php
//接收数据库名称
$dbname = $_GET[‘dbname’];
//获取字符集和校对集所有数据
//1.链接数据库
$link = @mysql_connect(‘localhost’,’root’,’’);
//2.设置编码
mysql_query(‘set names utf8’);
//3.准备SQL语句
$charset_sql = “show charset”;
$coll_sql = “show collation”;
//4.发送SQL语句到服务器
$char_res = mysql_query($charset_sql);
$coll_res = mysql_query($coll_sql);
//5.解析结果集资源
$char_rows = array();
while($char_row = mysql_fetch_assoc($char_res)){
$char_rows[] = $char_row;
}
//var_dump($char_rows);
$coll_rows = array();
while($coll_row = mysql_fetch_assoc($coll_res)){
$coll_rows[] = $coll_row;
}
?> <!DOCTYPE html>
3.处理页面:alterdb.php
