【发布时间】:2009-08-14 03:12:54
【问题描述】:
下面是我如何运行 mysql 查询的一些示例代码,我通过一个我认为可能会简单地切换数据库的函数来运行它们。
下面是我运行的 mysql 查询示例,下面是实际函数。
如果我决定使用此设置,是否很难更改为其他数据库类型,如 oracle 或其他类型?
只能修改函数还是需要更改每个页面上的查询?
$sql_photo = "select * from friend_user_photo where userid='$user_id' and defaultphoto='yes' order by auto_id desc";
$result_photo = executeQuery($sql_photo);
function executeQuery($sql) {
$result = mysql_query_2($sql);
if(mysql_error()){
$error = '<BR><center><font size="+1" face="arial" color="red">An Internal Error has Occured.<BR> The error has been recorded for review</font></center><br>';
// If admin is viewing then we show the query code and the error returned
if($_SESSION['auto_id'] == 1){
$sql_formatted = highlight_string( stripslashes( $sql ), true );
$error .= '<b>The MySQL Syntax Used</b><br>' . $sql_formatted . '<br><br><b>The MySQL Error Returned</b><br>' . mysql_error() ;
}
die($error);
}
return $result;
}
【问题讨论】: