This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 9 years ago.
I have a function that adds words in my database and for some reason it's putting them in all weird.
Here is my function :
function change_team($picname, $text){
include 'dbconnector.php';
$conn->query("UPDATE team SET tea_photo = '$picname', tea_text = $text WHERE tea_id = 1");
}
Then, I use a post form to put it in :
change_team($_POST['lala'], $_POST['text']);
$_POST['text'] = éÀéÀ works when I echo it before entering it into database, but in the database it does this: Éà É
I've tried everything, I've put my table as uft8_general_ci but it doesn't seem like it fixes anything.
In your dbconnector.php, do:
$conn->set_charset("utf8");
After connecting and selecting database. This will set the transmission encoding to UTF-8. (The table/column/db character set is just storage encoding).
Related
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 3 years ago.
I am trying to retrieve a number of rows from a mysql DB, some of which containing emojis, through the following function:
<?php
ini_set('mssql.charset', 'UTF-8');
//$mysqli->query("SET NAMES 'utf8'");
$mysqli->query("SET character_set_client=utf8mb4");
$mysqli->query("SET character_set_connection=utf8mb4");
$mysqli->query("SET character_set_results=utf8mb4");
$mysqli->set_charset("utf8");
$sth = $mysqli->query($query);
if (!$sth) error_log("error Json query: $query");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
//var_dump($rows);
print json_encode($rows, JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE);
?>
Yet each emoji occurrence is substituted by a variable number of question marks, yet
if I conversely execute the query of the php script directly on Sequel Pro, the emojis show correctly. Apparently there is therefore some error in the function above, but I tried anything, as you may see, without success.
How should the query be configured instead?
I thank Paul for the hint, the issue was related to the redundant use of:
$mysqli->set_charset("utf8")
that apparently replaced the previous commands, taking it out the emojis showed just fine.
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 4 years ago.
I migrated a project to a new host. So I transferred my files and my database. But since then, my sql queries with accented characters no longer work (NULL):
php file:
$ product = 'Gestion réseaux sociaux';
$ handle-> query ('SELECT social_networks FROM sale WHERE id_customer = "'. $ id. '" AND product = "'. $ product. '"');
In addition, the accented characters displayed in the view from the database are not displayed correctly.
However, the rest of the written text content that does not come from the database displays the accented characters.
I still put the meta:
<meta http-equiv = "Content-Type" content = "text / html; charset = UTF-8" />
So I deduce that it comes from the encoding of the database but it is identical to that of my former host (UTF8_unicode_ci)
What can be the reason for you?
Thank you in advance for your help !!
It was enough to add "charset=utf8" to PDO
new PDO("mysql:host=$this->host;dbname=$this->dbname;charset=utf8", $this->user, $this->password);
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 4 years ago.
I am having problems with accentuation in a project that I am giving maintenance.
Table MYQL using utf8_unicode_ci
String Error
$text = 'São Jos�'; #correct São José
echo utf8_decode($text); #print São Jos�
echo utf8_encode($text); #print São Jos�
How to solve using php 5.6?
Before you fetch result from the database, fire below query,
SET NAMES UTF8;
This will set the character-set and the results returned will be proper.
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I need to save text with language specific caracters in a mysql database.
I have setup the table and the field with utf8_general_ci
The test.php file to write into the database is also in utf8_general_ci:
<?php
include 'connect.php';
$x=$_GET["x"];
$d="INSERT INTO `test`
(`car`)
VALUES (' $x ')";
echo $d;
$resultins = mysql_query($d);
echo mysql_error();
echo "<br>".$id;
?>
In the browser I do:
/test.php?x=Vietnam_ờ_French_ç_German_ä
and the echo gives:
INSERT INTO test (car) VALUES (' Vietnam_á»_French_ç_German_ä ')
In database I get:
When I retrieve this data in another php and display it in the browserI get:
What am I missing?
Maybe before you start the select query, you should set the queries up to return UTF8 encoded string. First, use a <meta charset="utf-8"> in the head and before the query try this: mysqli_query($connection, "SET NAMES UTF8");. Hope it helps.
Place $dbc->set-charset('utf8') before any query.
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 12 months ago.
My trying to make an Ajax call to a PHP function that pulls out data from my database. I've run into a problem though.
My query looks like this
$query = "SELECT * FROM mytable WHERE field LIKE '%$string%'"
I then check on the number of rows returned by the query, but when i type in æ ø å then i my query returns 0 rows, although I know there are entries in the database that have æ ø å.. why is this
Set the connection to use UTF-8:
<?php
// MySQLi:
$connection = new MySQLi( /* ... credentials ...*/);
$connection->set_charset("utf8");
// MySQL:
$connection = mysql_connect(/* ... credentials ... */);
mysql_set_charset("utf8", $connection);
?>
in my case, I had to add this line:
mysqli_set_charset($con,"utf8mb4");