2015-02-24 47 views
-2

旧的查询用于获取管理员存储在数据库中的网站设置,如MyCompanyName或版权文本。这些是由管理员在后台添加的。如何更改PHP脚本以使用PDO?

<?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(); 
+0

你只能用这个1项纪录查询? – Alex 2015-02-24 16:55:13

+0

http://code.tutsplus.com/tutorials/php-database-access-are-you-doing-it-correctly--net-25338 – EddyTheDove 2015-02-24 16:55:30

+0

我修复了未正确格式化的隐藏代码。请学习如何使用这里的格式化工具 - 您只需选择您的代码并按代码按钮。甚至有预览窗格,所以没有理由发布无格式的代码。 – halfer 2015-02-24 17:09:35

回答

0

如果只有一排

$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.. 
} 
+0

非常感谢您花时间回答。是的,它目前只是一行。 – Gee 2015-02-25 15:16:28

+0

它现在正在实际工作。所以我错过了使用fetchAll()进行单行查询? – Gee 2015-02-25 15:17:36