php数据库测试代码 php测试数据库连接
PHP+MYSQL 应该是连接数据库的问题 希望有个具体的解决 或者测试方案
$link是链接mysql返回的资源,报错提示null given 说明你还没有连接mysql,就查询了
江津网站建设公司创新互联建站,江津网站设计制作,有大型网站制作公司丰富经验。已为江津近1000家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的江津做网站的公司定做!
php连接mysql数据库的测试代码是不是有很多种,哪种比较好呢?
链接数据库的语句?
define("HOST", "localhost");
define("USER", "数据库用户名");
define("PASSWORD", "数据库密码");
define("DATABASE", "数据库表");
$db=mysql_connect(HOST, USER, PASSWORD) or die ("mysql connected failed");
mysql_select_db(DATABASE, $db);
或
$DBHOST="localhost";
$DBUSER="用户名";
$DBPWD="密码";
$DBNAME="表名";
然后在页面中打开查询...
噢,对了.localhost是指本地.如果是远程的话.就得用ip
几种常用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 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
function dbConnect($hostname, $username, $pass, $db_name, $pconnect = 0)
{
global $connect;
$func = empty($pconnect) ? 'mysql_connect' : 'mysql_pconnect';
if (!$connect)
{
$connect = @$func($hostname, $username, $pass) or die("font size='2'Mysql_Error : " .
mysql_error() . "brMysql Error Num : " . mysql_errno() . "/font");
}
@mysql_select_db($db_name, $connect) or die("font size='2' Mysql_Error : " .
mysql_error() . "brMysql Error Num : " . mysql_errno() . "/font");
return $connect;
}
function query_error($query)
{
global $connect;
$temp_bar = "br=============================================================================br";
$result = mysql_query($query, $connect) or die("DB ERROR br" . $temp_bar .
"font size='2' Mysql_Query : " . $query . "br Mysql_Error : " . mysql_error
() . "br Mysql Error Num : " . mysql_errno() . "/font" . $temp_bar);
return $result;
}
function do_fetch_array($result, $result_type = MYSQL_ASSOC, $records = "one")
{
$icount = mysql_num_rows($result);
if ($records == "one")
{
return @mysql_fetch_array($result, $result_type);
} else
{
for ($i = 0; $i$icount; $i++)
{
$info[$i] = @mysql_fetch_array($result, $result_type);
}
mysql_free_result($result);
return $info;
}
}
function error_msg($msg, $url = "")
{
global $connect;
if ($connect)
{
mysql_close($connect);
}
switch ($url)
{
case "":
$url = "history.go(-1)";
break;
case "close":
$url = "window.close()";
break;
default:
$url = "document.location.href = '$url'";
break;
}
if (!empty($msg))
{
echo "script language='javascript'alert('$str');$url;/script";
} else
{
echo "script language='javascript'$url;/script";
}
exit;
}
$hostname = "localhost";
$username = "root";
$pass = "root";
$db_name = "books";
$connect = dbConnect($hostname, $username, $pass, $db_name);
$recs = query_error('select * from books');
$rec = do_fetch_array($recs,MYSQL_ASSOC,'all');
echo 'pre';
print_r($rec);
echo '/pre';
?
当前文章:php数据库测试代码 php测试数据库连接
本文路径:http://hbruida.cn/article/doeoeeh.html