php
mysql_connect("localhost","你的名字,一般为root","你的密码")or
die("cannot
connect
with
the
localhost.");
mysql_slect_db("你的数据库名字")
or
database.");
//这就是连接数据库的代码,简单的写法.
代码经修改,运行成功:
function dbConnect($hostname, $username, $pass, $db_name, $pconnect = 0)
{
global $connect;
$func = empty($pconnect) ? 'mysql_connect' : 'mysql_pconnect';
if (!$connect)
mysql_error() . "brMysql Error Num : " . mysql_errno() . "/font");
}
return $connect;
function query_error($query)
$temp_bar = "br=============================================================================br";
$result = mysql_query($query, $connect) or die("DB ERROR br" . $temp_bar .
() . "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 = "")
if ($connect)
mysql_close($connect);
switch ($url)
case "":
$url = "history.go(-1)";
break;
case "close":
$url = "window.close()";
default:
$url = "document.location.href = '$url'";
if (!empty($msg))
echo "script language='javascript'alert('$str');$url;/script";
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';
sybase_connect连上数据库.
语法: int sybase_connect(string [servername], string [username], string [password]);
返回值: 整数函数种类: 数据库功能 本函数用来打开与 Sybase 数据库的连接.
参数 servername 为欲连上的数据库服务器名称.
参数 username 及 password 可省略,分别为连接使用的帐号及密码.
使用本函数需注意早点关闭数据库,以减少系统的负担.
连接成功则返回数据库的连接代号,失败返回 false 值.
以上就是土嘎嘎小编为大家整理的php数据库测试代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!