下面是我如何运行我的mysql查询的一些示例代码,我通过一个函数运行它们,我认为它可以简化切换数据库。难以从MySQL切换到Oracle吗?
下面是我运行的一个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;
}
感谢,它看起来更难,然后我曾想过,也许看着支持多个数据库的软件将是一个可以研究的地方 – JasonDavis 2009-08-14 11:57:05