本文介绍了MySQL查询在phpmyadmin中工作,但不在php中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想从MySQL中的表中选择数据.我在php中的代码:

I want to select data from a table in MySQL.My code in php:

$conn = mysqli_connect($db_server, $db_benutzer, $db_passwort, $db_name);

$results= mysqli_query($conn, "SELECT * FROM `test` WHERE russia = 'привет'");
if(mysqli_num_rows($results) > 0) {
    echo "Results";
}
else {
    echo "No results";
}

mysqli_close($conn);

在这里,我得到没有结果".但是,当我直接在phpmyadmin中运行SELECT代码时,会得到结果.

Here I'm getting "No results". But when I run the SELECT-code directly in phpmyadmin i get a result.

怎么了?谢谢

推荐答案

查询中包含西里尔字符,因此可能有必要设置mySQL连接编码.如果您使用的是utf-8,请在mysqli_connect之后插入以下行:

You have cyrillic characters in your query, so it may be necessary to set mySQL connection encoding. If you are using utf-8, insert following line after mysqli_connect:

mysqli_query($conn, "SET NAMES 'utf8'");

或者如果您的脚本保存在Windows-1251中,请使用以下命令:mysqli_query($conn, "SET NAMES 'cp1251'");

Or if your script is saved in windows-1251, use the following: mysqli_query($conn, "SET NAMES 'cp1251'");

有关连接字符集和编码的更多信息,请参见手册

For more information about connection character sets and encodings please see the manual

为什么查询可以在phpMyAdmin中工作?因为它可能会在后台为您设置编码.

And why does the query work in phpMyAdmin? Because it probably sets encoding for you in the background.

这篇关于MySQL查询在phpmyadmin中工作,但不在php中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 10:27