用exec時要求apache有導(dǎo)出目錄的寫權(quán)限,例如apache有/path/to/目錄的寫權(quán)限:
創(chuàng)新互聯(lián)建站于2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站建設(shè)、成都網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元南州晴隆做網(wǎng)站,已為上家服務(wù),為南州晴隆各地企業(yè)和個人服務(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ù)庫連接工具,比如sqlyog,navicate等等;
開啟mysql服務(wù)器;
填寫數(shù)據(jù)庫連接信息(主機地址,用戶名密碼);
鏈接即可操作數(shù)據(jù)庫了。
常規(guī)方式
常規(guī)方式就是按部就班的讀取文件了。其余的話和上述方案一致。
// 讀取配置文件內(nèi)容
$handle = fopen("filepath", "r"); ? ? ? ? ? ?$content = fread($handle, filesize("filepath"));123
PHP解析XML
上述兩種讀取文件,其實都是為了PHP解析XML來做準(zhǔn)備的。關(guān)于PHP解析XML的方式的博客有很多。方式也有很多,像simplexml,XMLReader,DOM啦等等。但是對于比較小型的xml配置文件,simplexml就足夠了。
配置文件
?xml version="1.0" encoding="UTF-8" ?mysql
!-- 為防止出現(xiàn)意外,請按照此標(biāo)準(zhǔn)順序書寫.其實也無所謂了 --
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é)點,進而獲取相關(guān)的數(shù)據(jù)庫信息
$mysql = simplexml_load_string($content); ? ? ? ? ? ?// 將獲取到的xml節(jié)點信息賦值給關(guān)聯(lián)數(shù)組,方便接下來的方法調(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ù)庫配置文件信息出錯!/markbr /" );
} ? ? ? ?return $dbconfig;
}
}1234567891011121314151617181920212223242526272829
數(shù)據(jù)庫連接池
對于PHP程序而言,優(yōu)化永無止境。而數(shù)據(jù)庫連接池就在一定程度上起到了優(yōu)化的作用。其使得對用戶的每一個請求而言,無需每次都像數(shù)據(jù)庫申請鏈接資源。而是通過已存在的數(shù)據(jù)庫連接池中的鏈接來返回,從時間上,效率上,都是一個大大的提升。
于是,這里簡單的模擬了一下數(shù)據(jù)庫連接池的實現(xiàn)。核心在于維護一個“池”。
從池子中取,用畢,歸還給池子。
?php/**x
* ?PHP中的數(shù)據(jù)庫 工具類設(shè)計
* ?郭璞
* ?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文件丟失,無法進行配置文件的初始化操作!/markbr /" );
}else {
require './utils.php';
} ? ? ? ?// 初始化 配置文件信息
$this-dbconfig = XMLUtil::getDBConfiguration (); ? ? ? ?// 準(zhǔn)備好數(shù)據(jù)庫連接池“偽隊列”
$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ù)庫失??!/markbr /" );
array_push ( $this-dbpool, $conn );
}
} ? ?/**
* 從數(shù)據(jù)庫連接池中獲取一個數(shù)據(jù)庫鏈接資源
*
* @throws ErrorException
* @return mixed
*/
public function getConn() { ? ? ? ?if (count ( $this-dbpool ) = 0) { ? ? ? ? ? ?throw new ErrorException ( "mark數(shù)據(jù)庫連接池中已無鏈接資源,請稍后重試!/mark" );
} else { ? ? ? ? ? ?return array_pop ( $this-dbpool );
}
} ? ?/**
* 將用完的數(shù)據(jù)庫鏈接資源放回到數(shù)據(jù)庫連接池
*
* @param unknown $conn
* @throws ErrorException
*/
public function release($conn) { ? ? ? ?if (count ( $this-dbpool ) = $this-poolsize) { ? ? ? ? ? ?throw new ErrorException ( "mark數(shù)據(jù)庫連接池已滿/markbr /" );
} else {
array_push ( $this-dbpool, $conn );
}
}
}
給樓上點個贊。。。而且這種作業(yè)你自己找肯定也能找到。
百度啊。。很容易找到的啊。如果你看都看不懂,那只能去問你的老師了~畢竟愿意無聊給你當(dāng)保姆的人很能遇到~
Linux操作系統(tǒng)中安裝Mysql:
1. 從 下載二進制版的Mysql安裝包 //這個MYSQL是二進制版的,不用編譯
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個模版文件,我們選擇其中一個座位Mysql的配置文件,覆蓋/etc/my.cnf(系統(tǒng)默認的配置,其中設(shè)置了性能參數(shù)和Mysql的一些路徑參數(shù))
6. # cd /usr/local/mysql
# ./scripts/mysql_install_db --user=mysql
進入mysql目錄
//初試化表并且規(guī)定用mysql用戶來訪問。初始化表以后就開始給mysql和root用戶設(shè)定訪問權(quán)限
7. # chown -R root . //設(shè)定root能訪問/usr/local/mysql
8. # chown -R mysql data //設(shè)定mysql用戶能訪問/usr/local/mysql/data ,里面存的是mysql的數(shù)據(jù)庫文件.這個目錄是在/etc/my.cnf中有配置,在mysql_install_db時產(chǎn)生。
9. # chown -R mysql data/. //設(shè)定mysql用戶能訪問/usr/local/mysql/data/mysql下的所有文件
10. # chgrp -R mysql . //設(shè)定mysql組能夠訪問/usr/local/mysql
11. # /usr/local/mysql/bin/mysqld_safe --user=mysql
運行mysql
如果沒有問題的話,應(yīng)該會出現(xiàn)類似這樣的提示:
[1] 42264
# Starting mysqld daemon with databases from /usr/local/mysql/var
如果出現(xiàn) mysql ended這樣的語句,表示Mysql沒有正常啟動,你可以到log中查找問題,Log文件的通常在/etc/my.cnf中配置。大多數(shù)問題是權(quán)限設(shè)置不正確引起的。
12. 用如下命令修改MYSQL密碼
# /usr/local/mysql/bin/mysqladmin -u root password yourpassword //默認安裝密碼為空,為了安全你必須馬上修改.
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編譯目錄的一個腳本
//設(shè)置使mysql每次啟動都能自動運行
14. # service mysqld start
# netstat -atln
//啟動mysqld服務(wù)
//查看3306端口是否打開。要注意在防火墻中開放該端口。 詳細請看
操作系統(tǒng)下面 查看Apache+php+mysql在windows下的安裝與配置圖解
分享名稱:php的數(shù)據(jù)庫的網(wǎng)址 PHP數(shù)據(jù)庫
文章地址:http://chinadenli.net/article6/dodcpog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、定制開發(fā)、網(wǎng)站改版、自適應(yīng)網(wǎng)站、網(wǎng)站導(dǎo)航、網(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)