欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php 数据库连接的例子

程序员文章站 2022-06-08 08:20:22
...
数据库连接代码一:
/* database config */ 
$db_host  = 'localhost'; 
$db_user  = 'root'; 
$db_pass  = '123'; 
$db_database = 'todo'; 
/* end config */ 
$link = @mysql_connect($db_host,$db_user,$db_pass) or die('unable to establish a db connection'); 
mysql_set_charset('utf8'); 
mysql_select_db($db_database,$link);

数据库连接代码二:

error_reporting(e_all ^ e_notice); 
$db_host = ''; 
$db_user = ''; 
$db_pass = ''; 
$db_name = ''; 
@$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name); 
if (mysqli_connect_errno()) { 
    die('

could not connect to the database

please try again after a few moments.

'); } $mysqli->set_charset("utf8");


教程地址:

欢迎转载!但请带上文章地址^^