如何将mysql代码转换为pdo连接?因为我有一些网络问题。如何将mysql转换为PDO连接?
$gaSql['user'] = "root";
$gaSql['password'] = "";
$gaSql['db'] = "test";
$gaSql['server'] = "localhost";
// DB connection
function dbinit(&$gaSql) {
// if error rezults 500
function fatal_error($sErrorMessage = '') {
header($_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error');
die($sErrorMessage);
}
// connecting to mysql
if (!$gaSql['link'] = @mysql_connect($gaSql['server'], $gaSql['user'], $gaSql['password'])) {
fatal_error('Could not open connection to server');
}
// select the DB
if (!mysql_select_db($gaSql['db'], $gaSql['link'])) {
fatal_error('Could not select database');
}
}
对于PDO尝试阅读[手册](http://php.net/manual/en/pdo.connections.php)&this [post](https:// phpdelusions.net/pdo)。为什么你使用你的函数来查找错误而不是'mysql_error()'。 – gaurav