PHP code<?php
//连接数据
$con=mysql_connect("localhost","root","welcome123") or die("无法连接数据库".mysql_error());
//判断是否有my_project数据库
$existDB=mysql_select_db("my_project",$con);
//echo "没有my_project数据库";
if(!$existDB)
{
//创建数据库
$cdatabseSql="Create DATABASE my_project";
mysql_query($cdatabseSql,$con);
}
else
{
echo "有数据库";
}
//判断是否有sendmail表
$row=mysql_query("show databases");
$database=array();
$finddatabase="sendmail";
while ($result=mysql_fetch_array($row,MYSQL_ASSOC))
{
$database[]=$result['Database'];
}
unset($result,$row);
if(!in_array($finddatabase,$database))
{
echo "没有表";
$ctableSql="Create TABLE sendmail (
ID INT AUTO_INCREMENT PRIMARY KEY,
tomail nvarchar(50),
subject nvarchar(50),
message text
)";
mysql_query($ctableSql,$con);
}
else
{
echo "有表";
}
die();
?>