MySql中的查询返回一行,但我的php代码不返回

MySql中的查询返回一行,但我的php代码不返回,php,sql,mysqli,Php,Sql,Mysqli,我被这个愚蠢的问题缠住了。这段代码应该显示‘miejscowosci’表中的一行,但它似乎什么也不返回,尽管查询在myadmin上工作正常 $this->db = new mysqli(SRV, USR, PASS, DB_NAME); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $stmt = $this->db-&

我被这个愚蠢的问题缠住了。这段代码应该显示‘miejscowosci’表中的一行,但它似乎什么也不返回,尽管查询在myadmin上工作正常

$this->db = new mysqli(SRV, USR, PASS, DB_NAME);
if (mysqli_connect_errno()) 
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$stmt = $this->db->prepare("SELECT reg FROM miejscowosci WHERE nazwa = ?");
$stmt->bind_param("s", $city);
$stmt->execute();
if($stmt->store_result())
{
    echo $stmt->num_rows; //this echoes 0
}
$stmt->bind_result($this->region);
while($stmt->fetch())
{
    echo $this->region; //this echoes nothing
}

没有WHERE子句的查询给出了正确的输出。

好的,所以问题似乎是编码问题,我通过添加$mysqli->set\u charsetutf8解决了它;或者在php.ini中取消对排序规则\u server=utf8\u unicode\u ci和字符\u set\u server=utf8的注释。

您的$city集在哪里?我认为这是你们的问题,你们试图选择一个城市是空的区域,而这个区域并不存在。请在bind_参数之前尝试$city='something that existing in your database',这将返回结果:$city是该函数中的一个参数,它是已定义的。此外,将上面的查询更改为从Miejscowosi中选择reg,其中nazwa='sth\u that\u exists\u\u in\u db'给出了相同的结果。我没有发现任何错误,可能数据库中的数据有点错误。可能是城市名称前或城市名称后有空格导致此问题。