$config = [
'user' =>'root',
'passwd' =>'root',
]
try {
$db = new PDO('mysql:host=172.17.0.1port=3306dbname=test', $config['user'], $config['passwd'])
# 新建一张表 A
$db->exec('create table if not exists A (
id int unsigned not null primary key auto_increment comment \'主键id\'
)')
# 给表 A 新增一个字段 name
$db->exec('alter table A add column name varchar(50) not NULL default \'\' comment \'名称\'')
} catch (PODException $e) {
print("Error: " . $e->getMessage())
exit()
}
mysql_connect("localhost","root","") or die("登陆数据库失败")mysql_select_db("iPad") or die("连接数据库失败")
mysql_query("set names utf8")
$sql = "ALTER TABLE `表名` ADD `字段名` 数据类型"
mysql_query($sql)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)