Blogger Information
Blog 38
fans 0
comment 1
visits 30338
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 数据库连接的基本步骤;mysqli_connect() 2.数据库查询的基本步骤;mysqli_query()
1
Original
832 people have browsed it

数据库连接

实例

<?php
/**
 * 数据库连接
 * 1.连接数据库
 */
define('DB_HOST','127.0.0.1');
define('DB_USER','root');
define('DB_PASS','root');
define('DB_NAME','php');
define('DB_CHAR','utf8');

$db = @mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME) or die('数据库连接失败');
mysqli_set_charset($db,DB_CHAR);

运行实例 »

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

数据库基本查询

实例

<meta charset="utf-8">
<?php
//连接数据库

require 'mysqli_connect.php';

//查询
$sql = "SELECT name,salay FROM staff ";
//执行sql语句
$res = mysqli_query($db,$sql);
//判断$res存在在执行,否者就是没给他返回个false
if ($res){
// 将数据库中的值给取出来
    while ($row = mysqli_fetch_assoc($res)){
        var_export($row);
        echo '<hr>';
    }
}else{
    return false;
}
//释放结果集
mysqli_free_result($res);
//关闭连接
mysqli_close($db);

运行实例 »

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


Correction status:qualified

Teacher's comments:
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
  • 1
    2018-03-16 00:39:40
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!