mysqli方式与PDO方式,CRUD操作无异
<?php
$mysql = new mysqli();
$mysql->connect('localhost', 'root', 'pwd', 'php');
if ($mysql->connect_error)
echo $mysql->connect_error;
try {
$mysql = new PDO("mysql:host=localhost;dbname=php", 'root', 'pwd');
echo("connect success!<br/>");
$search = "select * from users";
$result = $mysql->query($search);
$dataArray = $result->fetchAll(PDO::FETCH_ASSOC);
print_r($dataArray);
echo("search success!");
} catch (PDOException $e) {
echo $e->getMessage();
}
$mysql->close();
exit();