gpt4 book ai didi

php - 为什么此查询返回大小写不同的列名?

转载 作者:行者123 更新时间:2023-11-29 06:13:17 24 4
gpt4 key购买 nike

我有一个 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

Column, index, and stored routine names are not case sensitive on any platform, nor are column aliases.

编辑:我为您检查了 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++;
}

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

关于php - 为什么此查询返回大小写不同的列名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8083436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com