如何更改 PHP 脚本以使用 PDO?

How to change a PHP script to use PDO?

旧查询用于获取管理员存储在数据库中的网站设置,例如 MyCompanyName 或 Copyright 文本。这些是由管理员添加到网站后端的。

<?php 

error_reporting (E_ALL ^ E_NOTICE);

include("connection.php");

include('english.php');

include("admin/include/function.php");

$query_general_setting=mysql_fetch_array(mysql_query("select * from general_setting where id=1 and g_id=1"));

if(basename(url())!="index.php" or basename(url())!="index.php?log=1"){

$explode_permistion=explode(",",$_SESSION['area_permistion']);

}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

    <head>

        <meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0">

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

        <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">

        <link href='http://fonts.googleapis.com/css?family=Exo+2&subset=latin,latin-ext' rel='stylesheet' type='text/css'>

        <link href="center/css/jquery/jquery-ui-1.10.3.custom.css" media="screen" rel="stylesheet" type="text/css" />

        <link href="center/css/center.css" media="screen" rel="stylesheet" type="text/css" />       

        <title><?php echo $query_store_setting['s_title'];?></title>

        <meta name="description" content="<?php echo $query_store_setting['s_description'];?>">

        <meta name="keywords" content="<?php echo $query_store_setting['s_keywords'];?>">

        <link rel="stylesheet" href="style.css"> 

</head>

改成这个没什么用:

$query_store_setting = $conn->query('SELECT * FROM general_setting WHERE id=1 and g_id=1')->fetchAll();

如果只有一行

$query_store_setting = $conn->query('SELECT * FROM general_setting WHERE id=1 and g_id=1')->fetch();

不止一个

$result = $conn->query('SELECT * FROM general_setting WHERE id=1 and g_id=1')->fetchAll();
 foreach($result as &$row) {
      $query_store_setting = $row;
      //do sth..
 }