MySQL query working in phpmyadmin but not in php

后端 未结 2 1884
庸人自扰
庸人自扰 2021-01-21 03:44

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($c         


        
2条回答
  •  盖世英雄少女心
    2021-01-21 04:18

    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'");
    

    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

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

提交回复
热议问题