這是哪裡錯了

來源:互聯網
上載者:User
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");
?>

Displaying members- $start+PAGE_SIZE,$totalRows)?>of














>






$rowCount = 0; foreach($members as $member){ $rowCount++; ?> } ?>
order=username">Username {?> order=firstname">First name {?> order=lastname">Last name {?>
getValueEncoded("id")?>">
getValueEncoded("username")?>
getValueEncoded("firstname")?> getValueEncoded("lastname")?>



0){?>
&
order=">Previous page


&order=">Next page



displayPageFooter();
?>


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");
?>

Displaying members- $start+PAGE_SIZE,$totalRows)?>of














>






$rowCount = 0; foreach($members as $member){ $rowCount++; ?> } ?>
order=username">Username {?> order=firstname">First name {?> order=lastname">Last name {?>
getValueEncoded("id")?>">
getValueEncoded("username")?>
getValueEncoded("firstname")?> getValueEncoded("lastname")?>



0){?>
&
order=">Previous page


&order=">Next page



displayPageFooter();
?>

... 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");
?>

Displaying members- $start+PAGE_SIZE,$totalRows)?>of














>






$rowCount = 0; foreach($members as $member){ $rowCount++; ?> } ?>
order=username">Username {?> order=firstname">First name {?> order=lastname">Last name {?>
getValueEncoded("id")?>">
getValueEncoded("username")?>
getValueEncoded("firstname")?> getValueEncoded("lastname")?>



0){?>
&
order=">Previous page


&order=">Next page



displayPageFooter();
?>

報錯的代碼沒有貼出來,
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);

要看getMembers函數裡面是如何寫的。

FROMmembersORDER !!
難道是沒有空格的原因 一坨拉出來了?

報錯的代碼沒有貼出來,
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);

要看getMembers函數裡面是如何寫的。
require_once"DataObject.class.php";
class Member extends DataObject{
protected $data = array(
"id"=>"",
"username"=>"",
"password"=>"",
"firstName"=>"",
"lastName"=>"",
"joinDate"=>"",
"gender"=>"",
"favoriteGenre"=>"",
"emailAddress"=>"",
"otherInterests"=>""
);
private $_genres = array(
"crime"=>"Crime",
"horror"=>"Horror",
"thriller"=>"Thriller",
"romance"=>"Romance",
"sciFi"=>"Sci-Fi",
"adventure"=>"Adventure",
"nonFiction"=>"Non-Fiction"
);
public static function getMembers($startRow,$numRows,$order){
$conn = parent::connect();
$sql = "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();
$members = array();
foreach($st->fetchAll() as $row){
$members[] = new Member($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". TBL_MEMBERS. " WHERE id = :id";
try{
$st = $conn->prepare($sql);
$st->bindValue(":id",$id,PDO::PARAM_INT);
$st->execute();
$row = $st->fetch();
parent::disconnect($conn);
if($row) return new Member($row);
}catch(PDOException $e){
parent::disconnect($conn);
die("Query failed:".$e->getMessage());
}
}

public function getGenderString(){
return($this->data["gender"]=="f")?"Female":"Male";
}
public function getFavoriteGenreString(){
return ($this->_genres[$this->data["favouriteGenre"]]);
}
}
?>

$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"; //複製這句試試

還是報錯了

前兩個錯誤是說你的父類DataObject的connect() 和 disconnect() 不是靜態方法,不能以靜態方式調用。解決辦法:在connect() 和 disconnect()前面加上 static 關鍵字。

第三個是說mydatabase.members 表不存在,檢查一下吧。

前兩個錯誤是說你的父類DataObject的connect() 和 disconnect() 不是靜態方法,不能以靜態方式調用。解決辦法:在connect() 和 disconnect()前面加上 static 關鍵字。

第三個是說mydatabase.members 表不存在,檢查一下吧。
你在那句sql語句裡改了什麼,好像看不到有改過的痕迹

from 後面和order 前面各加了一個空格

from 後面和order 前面各加了一個空格
這是什麼錯啊 為什麼是這樣改的

基本的sql文法,同學,該看書了。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.