网站首页 > 文章中心 > 其它

php数据库测试代码

作者:小编 更新时间:2023-09-04 14:24:59 浏览量:320人看过

php中和后台数据库连接的代码

php

mysql_connect("localhost","你的名字,一般为root","你的密码")or

die("cannot

connect

php数据库测试代码-图1

with

the

localhost.");

mysql_slect_db("你的数据库名字")

or

database.");

//这就是连接数据库的代码,简单的写法.

一段php 连接数据库的代码, 几个函数,再加几个变量..貌似代码有问题,请高手帮我看下

代码经修改,运行成功:

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';

几种常用PHP连接数据库的代码示例

sybase_connect连上数据库.

语法: int sybase_connect(string [servername], string [username], string [password]);

返回值: 整数函数种类: 数据库功能 本函数用来打开与 Sybase 数据库的连接.

参数 servername 为欲连上的数据库服务器名称.

参数 username 及 password 可省略,分别为连接使用的帐号及密码.

使用本函数需注意早点关闭数据库,以减少系统的负担.

连接成功则返回数据库的连接代号,失败返回 false 值.

以上就是土嘎嘎小编为大家整理的php数据库测试代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章