php简单连接数据库的代码怎么写,一个简单的连接到mysql数据库的php示例

if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])) send_404();

$dbHost = "localhost"; //Location Of Database usually its localhost

$dbUser = "xxxx"; //Database User Name

$dbPass = "xxxx"; //Database Password

$dbDatabase = "xxxx"; //Database Name

$db = mysql_connect($dbHost, $dbUser, $dbPass) or die ("Error connecting to database.");

mysql_select_db($dbDatabase, $db) or die ("Couldn't select the database.");

# This function will send an imitation 404 page if the user

# types in this files filename into the address bar.

# only files connecting with in the same directory as this

# file will be able to use it as well.

function send_404()

{

header('HTTP/1.x 404 Not Found');

print ''."n".

'

'."n".

'

404 Not Found'."n".

'

'."n".

'

Not Found

'."n".

'

The requested URL '.

str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']).

' was not found on this server.

'."n".

''."n";

exit;

}

# In any file you want to connect to the database,

# and in this case we will name this file db.php

# just add this line of php code (without the pound sign):

# include"db.php";

# once

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值