-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectMS.php
More file actions
25 lines (24 loc) · 780 Bytes
/
ConnectMS.php
File metadata and controls
25 lines (24 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
使用php连接mysql数据库的方法:常用mysqli 和 PDO
<?php
// mysqli
echo "<br>this vars to mysqli\t";
$mysqli = new mysqli("localhost", "wordpress", "123456", "test");
$result = $mysqli->query("SELECT * from test");
$row = $result->fetch_assoc();
echo htmlentities($row['name']);
// PDO
echo "<br>this vars to pdo\t";
$pdo = new PDO('mysql:host=localhost;dbname=test', 'wordpress', '123456');
$statement = $pdo->query("SELECT * from test");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['name']);
echo "<br>";
// mysql
echo "<br>this vars to mysql\t";
$c = mysql_connect("localhost", "wordpress", "123456");
mysql_select_db("test");
$result = mysql_query("SELECT * from test");
$row = mysql_fetch_assoc($result);
echo htmlentities($row['name']);
echo "<br>";
?>