php網(wǎng)站新建數(shù)據(jù)庫 php數(shù)據(jù)庫怎么創(chuàng)建

如何實(shí)現(xiàn)PHP自動(dòng)創(chuàng)建數(shù)據(jù)庫

你做好程序以后,把數(shù)據(jù)庫導(dǎo)出成sql文件

創(chuàng)新互聯(lián)長期為1000多家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為察哈爾右翼前企業(yè)提供專業(yè)的網(wǎng)站建設(shè)、成都網(wǎng)站制作察哈爾右翼前網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

1、連接數(shù)據(jù)庫

2、讀取這個(gè)sql文件里的sql語句,并執(zhí)行

3、生成一個(gè)數(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("打開文件錯(cuò)誤");

}?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語句錯(cuò)誤:第"?.?$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!";

}

?

php 怎么新建mysql 用戶 數(shù)據(jù)庫 和 設(shè)置數(shù)據(jù)庫權(quán)限啊

一、用PhpMyAdmin新建一個(gè)MySQL用戶.

1,用root登陸phpmyadmin

2,點(diǎn)權(quán)限

3,點(diǎn)創(chuàng)建一個(gè)用戶

4,選擇所有權(quán)限

執(zhí)行

二、使用可視化操作軟件,如phpmyadmin,mysqlcc等。

或者用命令行Create Database 數(shù)據(jù)庫名

三、for example

創(chuàng)建用戶vap,并分配權(quán)限:對數(shù)據(jù)庫vap的所有表可以從所有機(jī)器(第一句)和本地機(jī)器(第二局)進(jìn)行訪問,并擁有任意權(quán)限,密碼為vap

grant all privileges on vap.* to 'vap'@'%' identified by 'vap';

grant all privileges on vap.* to 'vap'@'localhost' identified by 'vap';

PHP網(wǎng)站安裝數(shù)據(jù)庫怎么填寫

數(shù)據(jù)表前綴:web_

數(shù)據(jù)庫主機(jī):localhost、127.0.0.1或者你的主機(jī)IP

數(shù)據(jù)庫名:535255

數(shù)據(jù)庫用戶名:root

數(shù)據(jù)庫密碼:1314255

phpstudy怎么創(chuàng)建數(shù)據(jù)庫

phpstudy數(shù)據(jù)庫創(chuàng)建步驟:

1、點(diǎn)擊打開phpstudy軟件,然后點(diǎn)擊mySQL管理器;

2、進(jìn)入到PHPmyadmin登陸界面,默認(rèn)賬號和密碼都是root;

3、登陸進(jìn)去后,如圖所示樣式;

4、然后,點(diǎn)擊數(shù)據(jù)庫,輸入想要的數(shù)據(jù)名稱,如:new,這個(gè)隨便取;

5、點(diǎn)擊創(chuàng)建后,成功后,如圖所示;

網(wǎng)頁題目:php網(wǎng)站新建數(shù)據(jù)庫 php數(shù)據(jù)庫怎么創(chuàng)建
標(biāo)題URL:http://muchs.cn/article4/dohsioe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、動(dòng)態(tài)網(wǎng)站、品牌網(wǎng)站制作、商城網(wǎng)站、標(biāo)簽優(yōu)化、微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)