Select PHP in tables with special characters

2

For some reason the DBA put "ç" on behalf of Mysql database tables and now I can not do select in those tables from php:

$conn = new mysqli($servername, $username, $password, $dbname);
$sql="select * from Tbl_login";
$result = $conn->query($sql);

The select wheel. But the:

$conn = new mysqli($servername, $username, $password, $dbname);
$sql="select * from Tbl_OrdemServiço";
$result = $conn->query($sql);

It does not get results ... but if I run this select on the bank it does.

Among the various tests I did I also gave this error:

  

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' o' at line 1

Can anyone help me?

    
asked by anonymous 23.10.2015 / 16:01

2 answers

1

The problem seems to be the incompatibility between the charsets and the code / client / file.

When the OP displays the error message:

  

have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' o' at line

This shows that ç has been converted in the wrong way.

The solution was to set the connection charset

 $conn->set_charset("utf8")
    
23.10.2015 / 16:46
0

To search for an exact word and / or that may cause some syntax error in sql use single quotes around the word, and in your query you are putting semicolons inside the query in;

$sql="select * from Tbl_OrdemServiço;";
                              _Aqui ^

Do the following

$sql = "SELECT * FROM 'Tbl_OrdemServiço'";
    
23.10.2015 / 16:42