Blogger Information
Blog 57
fans 0
comment 0
visits 46989
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Mysqli数据库连接
藍錄的博客
Original
954 people have browsed it

实例

<?php
/**
 * 数据库的连接
 */
//创建一个数据库连接,并返回mysqli对象
require 'config.php';
error_reporting(E_ALL ^E_WARNING);
//简化: 将连接参数转为变量或数组

$mysqli = new mysqli($db_host,$db_user,$db_pass, $db_name);

//判断是否连接成功?
if ($mysqli->connect_errno) {
    // 自定义错误提示信息
    die('连接错误'.$mysqli->connect_errno.': '. $mysqli->connect_error);
}

echo '<h1>连接成功</h1>';

// 设置默认数据库
//$mysqli->select_db($db_name);

//设置客【【】】户端默认的字符编码集
$mysqli->set_charset($db_charset);

// 将默认数据库在连接的时候,直接通过构造方法传入

运行实例 »

点击 "运行实例" 按钮查看在线实例


实例

<?php
$db_host = '127.0.0.1';
$db_user = 'root';
$db_pass = 'root';
$db_name = 'php';
$db_charset = 'utf8';

//$db = [
//    'host' => '127.0.0.1',
//    'user' => 'root',
//    'pass' => 'root',
//    'name' => 'php',
//    'charset' => 'utf8',
//];

运行实例 »

点击 "运行实例" 按钮查看在线实例

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post