mysql SELECT with 'from php数组不工作(因为' A '在php和mysql中看起来相同


mysql SELECT with 'A' from php array does not work (because `A` in php and mysql looks the same, but one written in Russian, another in English)

Array $_POST contains

(
[first_subcat] => А
[process_first_subcat_name_for_url] => 1
)

我知道在mysql列FirstSubtopicName一个字段值是A (varchar字段)。

查询是

SELECT TopicName FROM topics WHERE FirstSubtopicName = ?
$stmt->execute( array( $_POST['first_subcat'] ) );

并得到空数组

但是这样的查询是有效的

SELECT TopicName FROM topics WHERE FirstSubtopicName = ?
$stmt->execute( array( 'A' ) );

也可以

SELECT TopicName FROM topics WHERE FirstSubtopicName = 'A'

也适用于定义$_POST['first_subcat'] = 'A';

尝试更改为$stmt->execute( array( ''''.$_POST['first_subcat']. '''' ) );获取空。

尝试更改为'?'。还空

我做错了什么?

发现А是用非拉丁语写的(А是用俄语写的)。

А更改为А буква(检查),现在似乎一切正常。似乎在mysql中,我有A作为拉丁字符,但在POST中是俄罗斯的A…

在我的情况下,原因如下

A -英文字母

А -用俄语写的字母(кириллица,像С Д Ф Г Х等)

在mysql中A是英文的。但是在SELECT查询中,А是俄语。

两个A看起来一样,但对于SELECT查询它们是不同的。这是因为数组是空的

我猜查询正在寻找字符串。检查

$stmt->execute( array( (string)$_POST['first_subcat'] ) );