PHP连接数据库之PHP连接MYSQL数据库代码 < ?php
$mysql_server_name='localhost';
//改成自己的mysql数据库服务器
$mysql_username='root';
//改成自己的mysql数据库用户名
$mysql_password='12345678';
//改成自己的mysql数据库密码
$mysql_database='mycounter';
//改成自己的mysql数据库名
$conn=mysql_connect($mysql_server_name,
$mysql_username,$mysql_password,
$mysql_database);
$sql='CREATE DATABASE mycounter
DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
';
mysql_query($sql);
$sql='CREATE TABLE `counter`
(`id` INT(255) UNSIGNED NOT NULL
AUTO_INCREMENT ,`count` INT(255)
UNSIGNED NOT NULL DEFAULT 0,PRIMARY 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 com("ADODB.Connection");
$connstr = "DRIVER={Microsoft
Access Driver (*.mdb)};
DBQ=". realpath("data/db.mdb");
$conn->Open($connstr);
$rs = new com("ADODB.RecordSet");
$rs->Open("select *
from szd_t",$conn,1,1);
while(! $rs->eof) {
$f = $rs->Fields(1);
echo $f->value;
$rs->MoveNext();
}
?>
复制代码PHP连接数据库之PHP连接MS SQL数据库代码方法
1.安装SQL服务器并添加PHP的MSSQL扩展
2.使用以下代码连接并测试 < ?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 .= WHERE Country=USA
AND Left(HomePhone, 5) = (206);
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo < h1> . $numRows . Row .
($numRows == 1 ? : s) . Returned </ h1>;
while($row = mssql_fetch_array($result))
{
echo < li> . $row[Employee] . < /li>;
}
?>
复制代码PHP连接数据库之PHP连接Oracle数据库 < ?
if ($conn=Ora_Logon
{ echo "SUCCESS !
Connected to database/n";
}else
{echo "Failed :-(
Could not connect to database/n";}
Ora_Logoff($conn);
phpinfo();
?>
??????΄?הɘ?؍??ǜr
ԭ̻?ؖ???http://www.codesdown.com/viewthread.php?tid=37&fromuid=0