php数据库建立连接 php连接数据库表
几种常用PHP连接数据库的代码示例
PHP连接数据库之PHP连接MYSQL数据库代码
创新互联是一家专注于成都网站设计、网站建设与策划设计,林口网站建设哪家好?创新互联做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:林口等地区。林口做网站价格咨询:13518219792
?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 mycounter DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; ; mysql_query($sql); $sql= CREATE TABLE `counter` (`id` INT( ) UNSIGNED NOT NULL AUTO_INCREMENT `count` INT( ) UNSIGNED NOT NULL DEFAULT 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 ("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); echo h $numRows Row ($numRows == ? : s) Returned / h ; while($row = mssql_fetch_array($result)) { echo li $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_server_name='localhost';
$mysql_username='root';
$mysql_password='12345678';
$mysql_database='mycounter';
$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链接数据库有几种方式
mysqli:
?php
$servername = "localhost";
$username = "username";
$password = "password";
// 创建连接
$conn = new mysqli($servername, $username, $password);
// 检测连接
if ($conn-connect_error) {
die("连接失败: " . $conn-connect_error);
}
echo "连接成功";
?
也可以使用PDO进行链接,前提是你必须在php.ini中开启PDO:
?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
echo "连接成功";
}
catch(PDOException $e)
{
echo $e-getMessage();
}
?
建议使用PDO,功能更加强大,兼容各种数据库
文章题目:php数据库建立连接 php连接数据库表
当前地址:http://ybzwz.com/article/ddjojpo.html