<?php
/* 2011.7.27
*/
$demos =new Demo();
$dbname="create database tools";
$dbtabla="create table admin(name varchar(200),pass varchar(200))";
$values="insert into admin values('Feihacker','tools')";
$demos->CreateDB($dbname);
$demos->CreateDB($dbtabla,"tools");
$demos->CreateDB($values,"tools");
class Demo
{ /*執行插入操作
*/
public function CreateDB($sql,$name){
$conn =mysql_connect("localhost","root","root");//創建連接對象
if(!empty($name)) //創建表 //判斷是否為空
{
mysql_select_db($name,$conn); //選定數據庫
if(!mysql_query($sql)){ echo"error". mysql_error();} //mysql_query();執行sql語句
mysql_close($conn); //關閉連接
}
else
{
if(!mysql_query($sql)){ echo"error". mysql_error();}
mysql_close($conn);
}
}
}
?>
from:菲 blog