使用 é 进行查询作为 php drupal 7 中的列名称
我得到了这张表,其中的列名为 Catégorie
,我无法重命名(长话短说),而且 é 让我很烦恼。
我似乎无法查询该列。
我得到以下代码
$query_brands = "SELECT distinct catégorie as merk FROM GSProduct";
$resultBrands = $phpbb->query($query_brands);
$brandArr = array();
foreach($resultBrands as $brand){
$brandArr[$brand->merk] = $brand->merk;
}
在 mysql 中查询工作正常,但在 php 中我得到一个异常:
PDOException:在 meisjesschoenen_filter_form() 中(/home/mediaspe/domains/mediaspex.be/public_html/juniorsteps/sites/all/modules/meisjesschoenen/meisjesschoenen.module 的第 198 行)
我尝试将其放在 ' '
但后来我只得到 1 个空结果,而不是我应该得到的 7 个结果
不胜感激 很多!!
更新:
我在settings.php中找到了以下代码行,并添加了排序规则广告:
array (
'juniorsteps_gem' =>
array (
'database' => '*****',
'username' => '*****',
'password' => '*****?',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
'collation' => 'utf8_general_ci',
),
我还在mysql中发现我的数据库/表的排序规则也是utf8_general_ci,所以应该没问题。
UPDATE2(还无法自我回答)
问题是我的文件。 我已经使用 notepad++ 将文件从 ANSI 转换为 UTF 8,现在它可以工作了。
谢谢大家朝着正确的方向推动!
I got this table with a column name Catégorie
which I can't rename (long story) and that é is bothering me big time.
I can't seem to query that column.
I got the following code
$query_brands = "SELECT distinct catégorie as merk FROM GSProduct";
$resultBrands = $phpbb->query($query_brands);
$brandArr = array();
foreach($resultBrands as $brand){
$brandArr[$brand->merk] = $brand->merk;
}
In mysql the query works fine, but in php I get an exception:
PDOException: in meisjesschoenen_filter_form() (line 198 of /home/mediaspe/domains/mediaspex.be/public_html/juniorsteps/sites/all/modules/meisjesschoenen/meisjesschoenen.module)
I tried putting it between ' '
but then I just get 1 empty result instead of the 7 results I should get
Help is appreciated a lot!!
UPDATE:
I found the following lines of code in settings.php and I added the collation ad followed:
array (
'juniorsteps_gem' =>
array (
'database' => '*****',
'username' => '*****',
'password' => '*****?',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
'collation' => 'utf8_general_ci',
),
Also I found in mysql that the collation of my database/table also is utf8_general_ci so that should be ok.
UPDATE2 (could not self answer yet)
The problem was my file.
I've used notepad++ to convert my file from ANSI to UTF 8 and now it works.
Thx all for the push in the right direction!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您编写 SQL 语句的文件编码正确,例如 UTF-8。这是您正在使用的编辑器中的设置。
否则,您将向数据库发送错误的字符,因为您会收到无效的 PDO 异常。
Ensure that the file you're writing the SQL statement is correctly encoded, e.g. UTF-8. That's a setting in the editor you're using.
Otherwise you are sending the wrong characters to the database, because you get a PDO Exception an invalid one.
您应该使用`quote 而不是'。
尝试使用:
You should use ` quote instead of '.
Try to use: