为什么这个查询返回不同大小写的列名?


Why is this query returning a column name with different case?

我有一个mySQL表,其中一列名为roster_id(在表结构中都是小写)。我想在php中设置一个变量,但值没有设置好。

$contacts2 =  $db->get_results("SELECT * FROM roster WHERE status = 'pending'");
foreach ($contacts2 as $contact2) {
   $roster = $contact2->roster_id;
}

$roster没有被设置,所以我在$contacts2上做了一个print_r,这是我得到的结果:

Array
(
    [0] => stdClass Object
        (
            [roster_Id] => 12
            [people_id] => 182759
            [company_id] => 1
            [first_name] => Dennis
            [last_name] => Menace
            [title] => Test Account
            [email] => esther@esthermstrom.com
            [address1] => 1105 Test Pkwy
            [address2] => 
            [city] => Chicago
            [state_id] => 13
            [country_id] => 183
            [zip] => 60613
            [phone] => 333-333-3333
            [sm] => 1
            [lu] => 1
            [status] => pending
        )
)

roster_id被返回为roster_Id。知道为什么会这样吗?我可以通过修改php来使用替代拼写来解决这个问题,但是如果我不知道是什么原因导致了这个问题,我就无法确信它不会突然变回正确的大小写。

我不知道它是否有区别,但我们使用ezSQL数据库类

如果roster_Id是这样返回的,那么它就是这样创建的。在模式中更改它。你说"表结构中全部小写",但没有说你是如何检索模式的。尝试SHOW CREATE TABLE,然后使用ALTER TABLE来小写它。MySQL不介意:http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html

列、索引和存储例程名称在任何平台上都不区分大小写,列别名也不区分大小写。

编辑:我检查ez_sql源代码为您,这就是如何检索结果:
while ( $row = @mysql_fetch_object($this->result) )
{
  // Store relults as an objects within main array
  $this->last_result[$num_rows] = $row;
  $num_rows++;
}

它没有操作列。它也不会对您的查询字符串做任何真正邪恶的把戏。不,这是一个相当简单的工具,所以这样的问题只能来自数据库。