2012-05-02 10 views
0

私は持っているこの問題で私を助けてください。私は 'where句'の 'Unknown column' the_mother_church_id 'を取得します。 データベースの列名の名前を数回確認しましたが、名前が同じであると確信しています。データベースの不明な列の問題

ここで問題が発生する可能性があります。

おかげ

<?php 
    $past = mysql_query("SELECT * FROM the_mother_church WHERE the_mother_church_id = '1'") or die(mysql_error()); 
?> 

再びフィールドの名前を確認してくださいTABLE

CREATE TABLE IF NOT EXISTS `the_mother_church` (
    ` the_mother_church_id` int(255) NOT NULL, 
    `the_mother_church_head` varchar(255) NOT NULL, 
    ` the_mother_church_content` varchar(3000) NOT NULL, 
    ` the_mother_church_tags` varchar(255) NOT NULL, 
    ` the_mother_church_created` datetime NOT NULL, 
    ` the_mother_church_image` blob NOT NULL 
) ENGINE=InnoDB DEFAULT CHARSET=latin1; 
+2

あなたは私たちに、CREATE TABLE文を表示することができますか? – LeonardChallis

+0

、NOTは 'the_mother_church'(' the_mother_church_id' int型(255)NOT NULL、 'the_mother_church_head' VARCHAR(255)NOT NULL、 ' the_mother_church_content' VARCHAR(3000)NOT NULLで存在する場合、 'the_mother_church_tags' VARCHAR(255)のCREATE TABLE NOT NULL、 'the_mother_church_created' datetime NOT NULL、 ' the_mother_church_image' BLOB NOT NULL )ENGINE = InnoDB DEFAULT CHARSET = latin1; –

+0

@ user1365922:あなたの質問を編集することができますか(タグのすぐ下にある「編集」リンクを参照してください)、読みやすいように代わりに貼り付けてください。 – eggyal

答えて

2

(答えからのアップグレード)

あなたCREATE TABLE文では、列がオープニング引用とフィールド名の間にスペースが選ばれました示しています` the_mother_church_id`。次のいずれかの

  1. クエリ内のスペースで列名を使用します。

    SELECT * FROM the_mother_church WHERE ` the_mother_church_id` = '1' 
    
  2. は、列の名前を変更します。

    ALTER TABLE `the_mother_church` 
        CHANGE ` the_mother_church_id` 
          `the_mother_church_id`  int(255)  NOT NULL, 
        CHANGE ` the_mother_church_content` 
          `the_mother_church_content` varchar(3000) NOT NULL, 
        CHANGE ` the_mother_church_tags` 
          `the_mother_church_tags` varchar(255) NOT NULL, 
        CHANGE ` the_mother_church_created` 
          `the_mother_church_created` datetime  NOT NULL, 
        CHANGE ` the_mother_church_image` 
          `the_mother_church_image` blob   NOT NULL; 
    
1

を作成します。フィールド名をバッククォートで囲むことをお勧めします。

+2

OPは彼がすでにそれを数回チェックしていると言って、 'the_mother_church_id'は間違いなく** [予約語]ではないことを考えると(http://dev.mysql.com/doc/refman/5.5/en/reserved- words.html)MySQLで、私はこの回答が特に役立つとは確信していません... – eggyal

+0

フィールドがテーブルに存在する場合、このフィールドが使用されているSQLクエリではエラーです。 –

+0

彼はそれが何回か間違っていたことを確認して、フィールドをもう一度チェックしてください。有効な答え。 – LeonardChallis

0

テーブル構造のフィールド名の前に空白があります。
フィールド名からスペースを削除して、テーブルを再作成することをお勧めします。

` the_mother_church_id` 
^ an excessive space 
+0

ありがとう、私はそれを感謝します。 –

関連する問題