mysql8.0开始,默认编码是utf8mb4,但总有数据库会设置为gbk,所以也可能存在同样编码问题
<?php
define('DBHOST', '127.0.0.1');
define('DBUSER', 'root');
define('DBPW', 'password');
define('DBNAME', 'stu');
define('DBPORT', '3306');
$link=@mysqli_connect(DBHOST, DBUSER, DBPW, DBNAME, DBPORT);
for($i = 0 ; $i < 256 ; $i++){
$c = chr($i);
$name = @mysqli_real_escape_string($link,'201215121' . $c);
$sql = "SELECT * FROM `s` WHERE `sno` = '{$name}'";
$result=@mysqli_query($link,$sql);
$row = @mysqli_fetch_array($result,MYSQLI_NUM);
if ($row[0] == '201215121') {
echo "$i";
echo "{$c} <br/>";
}
}
输出$c时可能会出现乱码,所以可以echo utf8_encode($i);
这里是ascii码0-256所有的对照字符 https://blog.csdn.net/ttmice/article/details/50978054
mysql8.0基本也存在同样的问题,对于其他编码,需要自己再进行测试
tips:测试发现无论后面添加多少空格,查询都是可行的,猜测sql查询会自动去掉空格,不过其它空白符不行
测试代码:
<?php
define('DBHOST', '127.0.0.1');址
define('DBUSER', 'root');
define('DBPW', 'password');
define('DBNAME', 'stu');
define('DBPORT', '3306');
$link=@mysqli_connect(DBHOST, DBUSER, DBPW, DBNAME, DBPORT);
$name = @$_GET['name'];
$sql = "SELECT * FROM `s` WHERE `sno` = '{$name}'";
$result=@mysqli_query($link,$sql);
$row = @mysqli_fetch_array($result,MYSQLI_NUM);
echo $row[0];
?>