PHP does not send accents to Mysql bank

6

Good afternoon, guys!

I installed the OCOMON 2.0-RC6 Help-Desk system and I'm having the following problem:

PHP looks for the bank's accented words and displays them normally, this proves that the bank accepts accents and 'ç' and PHP displays them. No problems. The question is that I can only enter accented words or with 'ç' in the database by phpmyadmin or mysql (cli). For the direct OCOMON system I can not. There is a problem in sending the data contained in the fields, that is, when PHP sends to the bank. If I type in the description: "User contacted informing you that your printer has stopped printing.", No data will be entered in the bank in the 'description' field due to the accent of the word 'user'.

I've tried everything (change the collation - utf-8, latin1, iso-8859-1) ... it's bone ... help please. MySQL 5.5.28 + PHP 5.4.3

    
asked by anonymous 07.08.2014 / 20:48

8 answers

5

Try to place this line of code in the header of each page of your application, and especially in the files that are handling the data to be inserted in the database:
ini_set('default_charset', 'UTF-8');

If this does not work, check the charset encoding of your connection to the database. If you are using MySQL :

$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8',$link);

MySQLi :

$link = mysqli_connect("localhost","my_user","my_password","my_db");
mysqli_set_charset($link,"utf8");

PDO :

$db = new PDO(   'mysql:host='.DB_HOST.'; dbname='.DB_NAME, DB_USER, DB_PASS, 
            array(
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 
                PDO::ATTR_PERSISTENT => false,
                PDO::ATTR_EMULATE_PREPARES => false,
                PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
            )
        );
    
08.08.2014 / 16:48
4

What you really need is to unify the encoding being used.

Check the encoding in your HTML and use the same in the database. If the site encoding is UTF-8, put UTF-8 in the database.

Also check if the application is not doing some sort of conversion before sending it to the bank. Some bank libraries do this.

    
08.08.2014 / 16:23
2

Some steps are needed and I'll show them here:

1 - Make sure that the entire structure of your system is being encoded in a single charset: Example:

2-Tomakesurethateverythinggoeswellwiththecharactersenteredinthedatabase,afterthedatabaseconnectionscript,Ienterthefollowingcode:

mysql_query("SET NAMES 'utf8'");
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');

And taking these precautions, it's been a long time since I've had problems with accentuation by doing any of the CRUD operations on the bank of my sites and systems.

    
08.08.2014 / 16:39
1

I searched the sourceforge forum related to this project and already had a ticket on it.

look at this link link

Edited

I took a look at the connection code of this system, which alias is half old (2005) described in the header of the file conecta.class.php (although the author updated the project until 2009 according to the README.txt)

  • locate the "includes / classes / connect.class.php" file in the root directory of the application
  • Now license the line of code $this->con=mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD)or die(mysql_error());
  • Below the line above, add mysql_set_charset("UTF8", $this->con);
  •     
    07.08.2014 / 20:58
    1

    Place the collation of the database ALWAYS as utf8_general_ci and PHP code, when der insert do $nome = utf8_encode($_POST["nome"]);

    I've always used it like this, I've never had problems;)

        
    08.08.2014 / 16:56
    0

    Want to avoid problems with accents?

    Create / convert all files (PHP, HTML, CSS, all) to UTF8 without BOM.

    In html put the charset in utf8, in php using header content-type as utf8 and in the database specify at the moment of connection utf8 charset by PDO or mysqli_set_charset.

    You will never hear about charset problem again, so is this a problem?

        
    07.08.2014 / 20:56
    -1
    mysql_query("SET NAMES 'utf8'");
    mysql_query('SET character_set_connection=utf8');
    mysql_query('SET character_set_client=utf8');
    mysql_query('SET character_set_results=utf8');
    

    This worked for me. However my site is all encoded in UTF-8 and the general collation of the database as well.

    Always put this code after adding the connection to the database.

    And convert all pages of the site to UTF-8 without BOM (can do with Notepad ++).

        
    08.03.2016 / 05:00
    -1

    I searched the entire internet and put this code in the connection file, indicated in this post resolved:

    mysql_query("SET NAMES 'utf8'"); 
    mysql_query('SET character_set_connection=utf8'); 
    mysql_query('SET character_set_client=utf8'); 
    mysql_query('SET character_set_results=utf8'); 
    
        
    10.10.2016 / 01:34