Query failed:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROMmembersORDER BY username LIMIT 0,5' at line 1
找来找去都没发现错
FROMmembersORDER 这里没发现吗
把sql贴出来吧。
... FROM members ORDER BY username LIMIT 0,5
require_once("common.inc.php");
require_once("config.php");
require_once("Member.class.php");
$start = isset($_GET["start"])?(int)$_GET["start"]:0;
$order = isset($_GET["order"])?preg_replace("/[^a-zA-Z]/","",$_GET["order"]):"username";
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);
displayPageHeader("View book club members");
?>
Username {?> | First name {?> | Last name {?> |
---|---|---|
"> getValueEncoded("username")?> | getValueEncoded("firstname")?> | getValueEncoded("lastname")?> |
FROMmembersORDER 这里没发现吗
等级:Blank
#4 得分:0 回复于: 2013-11-15 15:40:40
require_once("common.inc.php");
require_once("config.php");
require_once("Member.class.php");
$start = isset($_GET["start"])?(int)$_GET["start"]:0;
$order = isset($_GET["order"])?preg_replace("/[^a-zA-Z]/","",$_GET["order"]):"username";
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);
displayPageHeader("View book club members");
?>
Username {?> | First name {?> | Last name {?> |
---|---|---|
"> getValueEncoded("username")?> | getValueEncoded("firstname")?> | getValueEncoded("lastname")?> |
... FROM members ORDER BY username LIMIT 0,5
等级:Blank
#4 得分:0 回复于: 2013-11-15 15:40:40
require_once("common.inc.php");
require_once("config.php");
require_once("Member.class.php");
$start = isset($_GET["start"])?(int)$_GET["start"]:0;
$order = isset($_GET["order"])?preg_replace("/[^a-zA-Z]/","",$_GET["order"]):"username";
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);
displayPageHeader("View book club members");
?>
Username {?> | First name {?> | Last name {?> |
---|---|---|
"> getValueEncoded("username")?> | getValueEncoded("firstname")?> | getValueEncoded("lastname")?> |
getMembers 関数の記述方法によって異なります。 ... ;
getMembers 関数の記述方法によって異なります。
require_once"DataObject.class.php";
class Member extends DataObject{
protected $data = array(
"username"=>"",
"パスワード"=>""、
"名"=>""、
"姓"=>""、
"参加日"=>""、
"性別"=>""、
" favouriteGenre"=>"",
"emailAddress"=>"",
"otherInterests"=>""
);
private $_genres = array(
"crime"=>"犯罪",
"ホラー"=>"ホラー"、
"スリラー"=>"スリラー"、
"ロマンス"=>"ロマンス"、
"sciFi"=>"サイエンスフィクション"、
"アドベンチャー"=> ;"アドベンチャー",
"nonFiction"=>"ノンフィクション"
);
public static function getMembers($startRow,$numRows,$order){
$conn =parent::connect(); = "SELECT SQL_CALC_FOUND_ROWS * FROM".TBL_MEMBERS."ORDER BY $order LIMIT :startRow,:numRows";
try{
$st = $conn->prepare($sql);
$st->bindValue( ":startRow",$startRow,PDO::PARAM_INT);
$st->bindValue(":numRows",$numRows,PDO::PARAM_INT);
$st->execute(); array();
foreach($st->fetchAll() as $row){
$members[] = 新しいメンバー($row) }
$st = $conn->query("SELECT found_rows( ) AS totalRows");
$row = $st->fetch();
parent::disconnect($conn);
return array($members,$row["totalRows"]);
}catch(PDOException) $e){
parent::disconnect($conn);
die("Query failed:".$e->getMessage());
}
}
public static function getMember($id){
$ conn =parent::connect();
$sql = "SELECT * FROM". WHERE id = :id";
$st = $conn->prepare($sql); ->bindValue(":id",$id,PDO::PARAM_INT);
$st->execute();
$row = $st->fetch(); );
if($row) return new Member($row);
}catch(PDOException $e){
parent::disconnect($conn);
die("クエリが失敗しました:".$e->getMessage ());
}
}
public function getGenderString(){
return($this->data["gender"]=="f")?"女性":"男性"; getFavoriteGenreString(){
return ($this->_genres[$this->data["favoriteGenre"]]);
}
}
?>
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM ".TBL_MEMBERS." ORDER BY $order LIMIT :startRow,:numRows"; //复制这句试试
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM ".TBL_MEMBERS." ORDER BY $order LIMIT :startRow,:numRows"; //复制这句试试
from の前後にスペースが追加されています
from の前後にスペースが追加されています
これは何が間違っていますか? なぜこのように変更されたのですか?
基本的な SQL 構文、クラスメート、本を読む時間です。