php连接数据库好 php连接数据库有什么用( 二 )


}else {
require './utils.php';
}// 初始化 配置文件信息
$this-dbconfig = XMLUtil::getDBConfiguration ();// 准备好数据库连接池“伪队列”
$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连接数据库失败!/markbr /" );
array_push ( $this-dbpool, $conn );
}
}/**
* 从数据库连接池中获取一个数据库链接资源
*
* @throws ErrorException
* @return mixed
*/
public function getConn() {if (count ( $this-dbpool ) = 0) {throw new ErrorException ( "mark数据库连接池中已无链接资源,请稍后重试!/mark" );
} else {return array_pop ( $this-dbpool );
}
}/**
* 将用完的数据库链接资源放回到数据库连接池
*
* @param unknown $conn
* @throws ErrorException
*/
public function release($conn) {if (count ( $this-dbpool ) = $this-poolsize) {throw new ErrorException ( "mark数据库连接池已满/markbr /" );
} else {
array_push ( $this-dbpool, $conn );
}
}
}
几种常用PHP连接数据库的代码示例PHP连接数据库之PHP连接MYSQL数据库代码
?php$mysql_server_name= localhost ;//改成自己的mysql数据库服务器$mysql_username= root ;//改成自己的mysql数据库用户名$mysql_password= ;//改成自己的mysql数据库密码$mysql_database= mycounter ;//改成自己的mysql数据库名$conn=mysql_connect($mysql_server_name $mysql_username $mysql_password $mysql_database);$sql= CREATE DATABASE mycounterDEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;;mysql_query($sql);$sql= CREATE TABLE `counter`(`id` INT( ) UNSIGNED NOT NULLAUTO_INCREMENT`count` INT( )UNSIGNED NOT NULL DEFAULTPRIMARY KEY( `id` ) ) TYPE = innodb; ;mysql_select_db($mysql_database $conn);$result=mysql_query($sql);//echo $sql;mysql_close($conn);echo "Hello!数据库mycounter已经成功建立!";?
PHP连接数据库之PHP连接ACCESS数据库代码方法
?$conn = new ("ADODB Connection");$connstr = "DRIVER={Microsoft Access Driver (* mdb)}; DBQ="realpath("data/db mdb");$conn Open($connstr);$rs = new ("ADODB RecordSet");$rs Open("select * from szd_t" $conn );while(! $rs eof) {$f = $rs Fields( );echo $f value;$rs MoveNext();}?
PHP连接数据库之PHP连接MS SQL数据库代码方法
安装SQL服务器并添加PHP的MSSQL扩展
使用以下代码连接并测试
?php$myServer = localhost; //主机$myUser = sa; //用户名$myPass = password; //密码$myDB = Northwind; //MSSQL库名$s = @mssql_connect($myServer$myUser$myPass)or die(Couldnt connect to SQL Server on $myServer);$d = @mssql_select_db($myDB$s)or die(Couldnt open database $myDB);$query = SELECT TitleOfCourtesy+ +FirstName+ +LastName AS Employee ;$query= FROM Employees ;$query= WHERECountry=USA AND Left(HomePhone) = ( );$result = mssql_query($query);$numRows = mssql_num_rows($result);echoh$numRowsRow($numRows ==? : s)Returned / h ;while($row = mssql_fetch_array($result)){echoli$row[Employee]/li;}?
PHP连接数据库之PHP连接Oracle数据库
PHP提供了两套函数与Oracle连接 分别是ORA_和OCI函数 其中ORA_函数略显陈旧 OCI函数更新据说更好一些 两者的使用语法几乎相差无几 你的PHP安装选项应该可以支持两者的使用
?if ($conn=Ora_Logon("user@TNSNAME" "password")){ echo "SUCCESS ! Connected to databasen";}else{echo "Failed : ( Could not connect to databasen";}Ora_Logoff($conn);phpinfo();?lishixinzhi/Article/program/PHP/201405/30761
怎么将php与数据库连接php链接mysql必备条件:
已安装mysql数据库;
检查php环境是否已开启mysql扩展(一般情况下是开启的);
检查方法:a.使用phpinfo();函数,看有没有mysql项;b.打开php.ini文件,检查php_mysql.dll前分号是否已取掉 。

推荐阅读