21,893
社区成员




<?php
// we connect to example.com and port 3307
$link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
// we connect to localhost at port 3307
$link = mysql_connect('127.0.0.1:3307', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}else{
// 建立表
$query = "CREATE TABLE `TableName` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(20) NOT NULL,
`content` mediumtext NOT NULL,
`keyw` varchar(20) NOT NULL,
`author` varchar(20) NOT NULL,
`lastdate` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 AUTO_INCREMENT=75";
/*
// 如果删除表,就用下面这个语句
$query = "DROP TABLE IF EXISTS `TableName`";
*/
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
}
mysql_close($link);
?>
$sql = "DROP TABLE IF EXISTS `user`";//执行会删除 user 表
$sql = "CREATE TABLE `user` (
`id` mediumint(8) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8";//执行回添加user表