用exec時(shí)要求apache有導(dǎo)出目錄的寫權(quán)限,例如apache有/path/to/目錄的寫權(quán)限:
創(chuàng)新互聯(lián)建站于2013年開(kāi)始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、成都網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元南州晴隆做網(wǎng)站,已為上家服務(wù),為南州晴隆各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
?php
$cmd = "mysqldump -utest -ptest mydb mytable /path/to/outfile.sql";
exec($cmd);
?
導(dǎo)出的outfile.sql文件中既有結(jié)構(gòu),也有數(shù)據(jù)。
下載輔助數(shù)據(jù)庫(kù)連接工具,比如sqlyog,navicate等等;
開(kāi)啟mysql服務(wù)器;
填寫數(shù)據(jù)庫(kù)連接信息(主機(jī)地址,用戶名密碼);
鏈接即可操作數(shù)據(jù)庫(kù)了。
常規(guī)方式
常規(guī)方式就是按部就班的讀取文件了。其余的話和上述方案一致。
// 讀取配置文件內(nèi)容
$handle = fopen("filepath", "r"); ? ? ? ? ? ?$content = fread($handle, filesize("filepath"));123
PHP解析XML
上述兩種讀取文件,其實(shí)都是為了PHP解析XML來(lái)做準(zhǔn)備的。關(guān)于PHP解析XML的方式的博客有很多。方式也有很多,像simplexml,XMLReader,DOM啦等等。但是對(duì)于比較小型的xml配置文件,simplexml就足夠了。
配置文件
?xml version="1.0" encoding="UTF-8" ?mysql
!-- 為防止出現(xiàn)意外,請(qǐng)按照此標(biāo)準(zhǔn)順序書寫.其實(shí)也無(wú)所謂了 --
hostlocalhost/host
userroot/user
password123456/password
dbtest/db
port3306/port/mysql12345678910
解析
?php/**
* 作為解析XML配置文件必備工具
*/class XMLUtil {
public static $dbconfigpath = "./db.config.xml"; ? ?public static function getDBConfiguration() {
$dbconfig = array (); ? ? ? ?try { ? ? ? ? ? ?// 讀取配置文件內(nèi)容
$handle = fopen(self::$dbconfigpath, "r"); ? ? ? ? ? ?$content = fread($handle, filesize(self::$dbconfigpath)); ? ? ? ? ? ?// 獲取xml文檔根節(jié)點(diǎn),進(jìn)而獲取相關(guān)的數(shù)據(jù)庫(kù)信息
$mysql = simplexml_load_string($content); ? ? ? ? ? ?// 將獲取到的xml節(jié)點(diǎn)信息賦值給關(guān)聯(lián)數(shù)組,方便接下來(lái)的方法調(diào)用
$dbconfig['host'] = $mysql-host; ? ? ? ? ? ?$dbconfig['user'] = $mysql-user; ? ? ? ? ? ?$dbconfig['password'] = $mysql-password; ? ? ? ? ? ?$dbconfig['db'] = $mysql-db; ? ? ? ? ? ?$dbconfig['port'] = $mysql-port; ? ? ? ? ? ?// 將配置信息以關(guān)聯(lián)數(shù)組的形式返回
return $dbconfig;
} catch ( Exception $e ) { ? ? ? ? ? ?throw new RuntimeException ( "mark讀取數(shù)據(jù)庫(kù)配置文件信息出錯(cuò)!/markbr /" );
} ? ? ? ?return $dbconfig;
}
}1234567891011121314151617181920212223242526272829
數(shù)據(jù)庫(kù)連接池
對(duì)于PHP程序而言,優(yōu)化永無(wú)止境。而數(shù)據(jù)庫(kù)連接池就在一定程度上起到了優(yōu)化的作用。其使得對(duì)用戶的每一個(gè)請(qǐng)求而言,無(wú)需每次都像數(shù)據(jù)庫(kù)申請(qǐng)鏈接資源。而是通過(guò)已存在的數(shù)據(jù)庫(kù)連接池中的鏈接來(lái)返回,從時(shí)間上,效率上,都是一個(gè)大大的提升。
于是,這里簡(jiǎn)單的模擬了一下數(shù)據(jù)庫(kù)連接池的實(shí)現(xiàn)。核心在于維護(hù)一個(gè)“池”。
從池子中取,用畢,歸還給池子。
?php/**x
* ?PHP中的數(shù)據(jù)庫(kù) 工具類設(shè)計(jì)
* ?郭璞
* ?2016年12月23日
*
**/class DbHelper { ? ?private $dbconfig; ? ?private $dbpool; ? ?public $poolsize; ? ?public function __construct($poolsize = 20) { ? ? ? ?if (! file_exists ( "./utils.php" )) { ? ? ? ? ? ?throw new RuntimeException ( "markutils.php文件丟失,無(wú)法進(jìn)行配置文件的初始化操作!/markbr /" );
}else {
require './utils.php';
} ? ? ? ?// 初始化 配置文件信息
$this-dbconfig = XMLUtil::getDBConfiguration (); ? ? ? ?// 準(zhǔn)備好數(shù)據(jù)庫(kù)連接池“偽隊(duì)列”
$this-poolsize = $poolsize;
$this-dbpool = array (); ? ? ? ?for($index = 1; $index = $this-poolsize; $index ++) {
$conn = mysqli_connect ( $this-dbconfig ['host'], $this-dbconfig ['user'], $this-dbconfig ['password'], $this-dbconfig ['db'] ) or die ( "mark連接數(shù)據(jù)庫(kù)失敗!/markbr /" );
array_push ( $this-dbpool, $conn );
}
} ? ?/**
* 從數(shù)據(jù)庫(kù)連接池中獲取一個(gè)數(shù)據(jù)庫(kù)鏈接資源
*
* @throws ErrorException
* @return mixed
*/
public function getConn() { ? ? ? ?if (count ( $this-dbpool ) = 0) { ? ? ? ? ? ?throw new ErrorException ( "mark數(shù)據(jù)庫(kù)連接池中已無(wú)鏈接資源,請(qǐng)稍后重試!/mark" );
} else { ? ? ? ? ? ?return array_pop ( $this-dbpool );
}
} ? ?/**
* 將用完的數(shù)據(jù)庫(kù)鏈接資源放回到數(shù)據(jù)庫(kù)連接池
*
* @param unknown $conn
* @throws ErrorException
*/
public function release($conn) { ? ? ? ?if (count ( $this-dbpool ) = $this-poolsize) { ? ? ? ? ? ?throw new ErrorException ( "mark數(shù)據(jù)庫(kù)連接池已滿/markbr /" );
} else {
array_push ( $this-dbpool, $conn );
}
}
}
給樓上點(diǎn)個(gè)贊。。。而且這種作業(yè)你自己找肯定也能找到。
百度啊。。很容易找到的啊。如果你看都看不懂,那只能去問(wèn)你的老師了~畢竟愿意無(wú)聊給你當(dāng)保姆的人很能遇到~
Linux操作系統(tǒng)中安裝Mysql:
1. 從 下載二進(jìn)制版的Mysql安裝包 //這個(gè)MYSQL是二進(jìn)制版的,不用編譯
2. # chmod 755 mysql-standard-5.0.15-linux-gnu-i686-glibc23.tar.gz
//
3. # tar xfz mysql-standard-5.0.15-linux-gnu-i686-glibc23.tar.gz //將解壓后生成的目錄,復(fù)制到/usr/local/下并改名為mysql
4. # groupadd mysql
# useradd mysql -g mysql // 建立mysql組
//建立mysql用戶并且加入到mysql組中
5. # cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
在 support-files目錄下有4個(gè)模版文件,我們選擇其中一個(gè)座位Mysql的配置文件,覆蓋/etc/my.cnf(系統(tǒng)默認(rèn)的配置,其中設(shè)置了性能參數(shù)和Mysql的一些路徑參數(shù))
6. # cd /usr/local/mysql
# ./scripts/mysql_install_db --user=mysql
進(jìn)入mysql目錄
//初試化表并且規(guī)定用mysql用戶來(lái)訪問(wèn)。初始化表以后就開(kāi)始給mysql和root用戶設(shè)定訪問(wèn)權(quán)限
7. # chown -R root . //設(shè)定root能訪問(wèn)/usr/local/mysql
8. # chown -R mysql data //設(shè)定mysql用戶能訪問(wèn)/usr/local/mysql/data ,里面存的是mysql的數(shù)據(jù)庫(kù)文件.這個(gè)目錄是在/etc/my.cnf中有配置,在mysql_install_db時(shí)產(chǎn)生。
9. # chown -R mysql data/. //設(shè)定mysql用戶能訪問(wèn)/usr/local/mysql/data/mysql下的所有文件
10. # chgrp -R mysql . //設(shè)定mysql組能夠訪問(wèn)/usr/local/mysql
11. # /usr/local/mysql/bin/mysqld_safe --user=mysql
運(yùn)行mysql
如果沒(méi)有問(wèn)題的話,應(yīng)該會(huì)出現(xiàn)類似這樣的提示:
[1] 42264
# Starting mysqld daemon with databases from /usr/local/mysql/var
如果出現(xiàn) mysql ended這樣的語(yǔ)句,表示Mysql沒(méi)有正常啟動(dòng),你可以到log中查找問(wèn)題,Log文件的通常在/etc/my.cnf中配置。大多數(shù)問(wèn)題是權(quán)限設(shè)置不正確引起的。
12. 用如下命令修改MYSQL密碼
# /usr/local/mysql/bin/mysqladmin -u root password yourpassword //默認(rèn)安裝密碼為空,為了安全你必須馬上修改.
13. # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 700 /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on //copy編譯目錄的一個(gè)腳本
//設(shè)置使mysql每次啟動(dòng)都能自動(dòng)運(yùn)行
14. # service mysqld start
# netstat -atln
//啟動(dòng)mysqld服務(wù)
//查看3306端口是否打開(kāi)。要注意在防火墻中開(kāi)放該端口。 詳細(xì)請(qǐng)看
操作系統(tǒng)下面 查看Apache+php+mysql在windows下的安裝與配置圖解
分享名稱:php的數(shù)據(jù)庫(kù)的網(wǎng)址 PHP數(shù)據(jù)庫(kù)
文章地址:http://www.chinadenli.net/article6/dodcpog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、定制開(kāi)發(fā)、網(wǎng)站改版、自適應(yīng)網(wǎng)站、網(wǎng)站導(dǎo)航、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)