// 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']);
?>