Blogger Information
Blog 34
fans 2
comment 2
visits 22734
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
mysqli_connect()、mysqli_query()用法说明 20180424-10:54
AsNwds_MIS王的博客
Original
1081 people have browsed it

实例mysqli_config.php

<?php
/医院
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/24
 * Time: 7:42
 */
define ('DB_HOST', 'localhost');
define ('DB_USER', 'root');
define ('DB_PASS', 'root');
define ('DB_NAME', 'php');
define ('DB_CHAR', 'utf8');

运行实例 »

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

实例

<?php
/医院
mysqli_connect()
 */
//1、连接数据库 require 不是函数
require 'mysqli_config.php';

//2、执行查询操作
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASS);

//3、检查连接
if (!$con){
    die("连接错误:".mysqli_connect_error());
} echo "连接成功";

运行实例 »

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

mysqli_connect() 函数打开一个到 MySQL 服务器的新的连接。

语法:mysqli_connect(host,username,password,dbname,port,socket);

注意: define的后面一定要带有空格 例 define ('DB_HOST', 'localhost');

实例

<?php
/医院
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/24
 * Time: 8:17
 */
//1、连接数据库
require 'mysqli_config.php';
//2、执行查询
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);

$sql="select * from user";

$res = mysqli_query($con,$sql);
//$rows = mysqli_fetch_assoc($res);
$rows = mysqli_fetch_array($res); //用结果组成数组
var_export($rows);

//3、释放结果集(仅针对select)
mysqli_free_result($res);

//4.关闭数据库连接
mysqli_close($con);

运行实例 »

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

mysqli_query() 函数执行某个针对数据库的查询

语法 : mysqli_query(connection,query,resultmode);


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