一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php 数据库连接的例子

时间:2022-06-24 19:07:07 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码

/* 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");

热门栏目