Blogger Information
Blog 6
fans 0
comment 0
visits 4300
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php7.0 连接mysql 测试
littler_two的博客
Original
1378 people have browsed it

<?php
// mysqli

// php7.0以上连接方式

// phpinfo()
// 连接数据库,默认选择cms数据库
$mysqli = new mysqli("localhost", "root", "", "cms");
// 插入语句
$query = "insert cms_admin(aname,pwd)
            VALUE
            ('xiaomi',md5('123456'))";
// 执行插入语句
$result = $mysqli->query($query);
var_dump($result);
// 关闭数据库(释放内存)
$mysqli->close();
$mysqli = new mysqli("example.com", "user", "password", "database");
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $result->fetch_assoc();
echo htmlentities($row['_message']);

// PDO

$pdo = new PDO('mysql:host=example.com;dbname=database', 'user', 'password');
$statement = $pdo->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);

// mysql

// php7.0以下连接方式

$c = mysql_connect("example.com", "user", "password");
mysql_select_db("database");
$result = mysql_query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = mysql_fetch_assoc($result);
echo htmlentities($row['_message']);

?>

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