Home > php教程 > php手册 > php 数据库连接的例子

php 数据库连接的例子

WBOY
Release: 2016-05-26 15:22:04
Original
1162 people have browsed it

数据库连接代码一:

/* 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);
Copy after login

数据库连接代码二:

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(&#39;<h1>could not connect to the database</h1><h2>please try again after a few moments.</h2>&#39;); 
}
$mysqli->set_charset("utf8");
Copy after login

                           


教程地址:

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template