你做好程序以后,把數(shù)據(jù)庫導(dǎo)出成sql文件(這個文件里就已經(jīng)有了一下創(chuàng)建數(shù)據(jù)表,添加數(shù)據(jù)記錄等的一些sql語句了)
成都創(chuàng)新互聯(lián)專注于通渭企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,成都做商城網(wǎng)站。通渭網(wǎng)站建設(shè)公司,為通渭等地區(qū)提供建站服務(wù)。全流程按需求定制制作,專業(yè)設(shè)計,全程項目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
新建一個安裝文件:
1、連接數(shù)據(jù)庫(安裝的時候不是要填寫一些數(shù)據(jù)庫連接參數(shù)等嗎)
2、讀取這個sql文件里的sql語句,并執(zhí)行
3、生成一個數(shù)據(jù)庫連接參數(shù)的php文件
就這么簡單,思路是這樣啊,具體這么實現(xiàn),你自己慢慢研究
創(chuàng)建數(shù)據(jù)庫:create database 數(shù)據(jù)庫名
創(chuàng)建數(shù)據(jù)表:
CREATE TABLE `users` (
`id` tinyint(10) auto_increment primary key NOT NULL,
`username` varchar(30) NOT NULL,
`age` int(10) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
執(zhí)行這兩個sql語句就行
你做好程序以后,把數(shù)據(jù)庫導(dǎo)出成sql文件
1、連接數(shù)據(jù)庫
2、讀取這個sql文件里的sql語句,并執(zhí)行
3、生成一個數(shù)據(jù)庫連接參數(shù)的php文件
?php
$con?=?mysql_connect("localhost","peter","abc123");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
if?(mysql_query("CREATE?DATABASE?my_db",$con))
{
echo?"Database?created";
}
else
{
echo?"Error?creating?database:?"?.?mysql_error();
}
mysql_close($con);
?
?php
class?ReadSql?{
//數(shù)據(jù)庫連接
protected?$connect?=?null;
//數(shù)據(jù)庫對象
protected?$db?=?null;
//sql文件
public?$sqlFile?=?"";
//sql語句集
public?$sqlArr?=?array();
public?function?__construct($host,?$user,?$pw,?$db_name)?{
$host?=?empty($host)???C("DB_HOST")?:?$host;
$user?=?empty($user)???C("DB_USER")?:?$user;
$pw?=?empty($pw)???C("DB_PWD")?:?$pw;
$db_name?=?empty($db_name)???C("DB_NAME")?:?$db_name;
//連接數(shù)據(jù)庫
$this-connect?=?mysql_connect($host,?$user,?$pw)?or?die("Could?not?connect:?"?.?mysql_error());
$this-db?=?mysql_select_db($db_name,?$this-connect)?or?die("Yon?can?not?select?the?table:"?.?mysql_error());
}
//導(dǎo)入sql文件
public?function?Import($url)?{
$this-sqlFile?=?file_get_contents($url);
if?(!$this-sqlFile)?{
exit("打開文件錯誤");
}?else?{
$this-GetSqlArr();
if?($this-Runsql())?{
return?true;
}
}
}
//獲取sql語句數(shù)組
public?function?GetSqlArr()?{
//去除注釋
$str?=?$this-sqlFile;
$str?=?preg_replace('/--.*/i',?'',?$str);
$str?=?preg_replace('/\/\*.*\*\/(\;)?/i',?'',?$str);
//去除空格?創(chuàng)建數(shù)組
$str?=?explode(";\n",?$str);
foreach?($str?as?$v)?{
$v?=?trim($v);
if?(empty($v))?{
continue;
}?else?{
$this-sqlArr[]?=?$v;
}
}
}
//執(zhí)行sql文件
public?function?RunSql()?{
foreach?($this-sqlArr?as?$k?=?$v)?{
if?(!mysql_query($v))?{
exit("sql語句錯誤:第"?.?$k?.?"行"?.?mysql_error());
}
}
return?true;
}
}
//范例:
header("Content-type:text/html;charset=utf-8");
$sql?=?new?ReadSql("localhost",?"root",?"",?"log_db");
$rst?=?$sql-Import("./log_db.sql");
if?($rst)?{
echo?"Success!";
}
?
phpstudy數(shù)據(jù)庫創(chuàng)建步驟:
1、點擊打開phpstudy軟件,然后點擊mySQL管理器;
2、進入到PHPmyadmin登陸界面,默認賬號和密碼都是root;
3、登陸進去后,如圖所示樣式;
4、然后,點擊數(shù)據(jù)庫,輸入想要的數(shù)據(jù)名稱,如:new,這個隨便取;
5、點擊創(chuàng)建后,成功后,
網(wǎng)站名稱:怎么創(chuàng)建php數(shù)據(jù)庫 phpstorm創(chuàng)建數(shù)據(jù)庫
路徑分享:http://muchs.cn/article6/dospeog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、網(wǎng)站設(shè)計公司、App設(shè)計、軟件開發(fā)、搜索引擎優(yōu)化、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容