エラーメッセージ: 「SQL 構文にエラーがあります。MySQL サーバーのバージョンに対応するマニュアルで、1 行目の 'portfolio' 付近で使用する正しい構文を確認してください」
問題のあるコードは次のとおりです。
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$host="****"; // Host name
$username="****"; // Mysql username
$password="****"; // Mysql password
$db_name="a9307665_br"; // Database name
$tbl_name="portfolio"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die(mysql_error());
mysql_select_db("$db_name")or die(mysql_error());
$query_getPosts = "SELECT post_id, title, updated FROM $tbl_name ORDER BY updated DESC";
$getPosts = mysql_query($tbl_name) or die(mysql_error());
$row_getPosts = mysql_fetch_assoc($getPosts);
$totalRows_getPosts = mysql_num_rows($getPosts);
?>
そして、エラーはMySQLベースであるため、これがエラーの原因となっているコード行であると推測します。
$query_getPosts = "SELECT post_id, title, updated FROM $tbl_name ORDER BY updated DESC";
誰かが私を正しい方向に向けることができますか?
更新:結果:echo $query_getPosts;
SELECT post_id, title, updated FROM `portfolio` ORDER BY updated DESC