0

I'm having a problem while executing a SELECT query. Namely, I use an external API to analyze whether articles are in my database. I noticed that the source encoding is UTF-8 while my base encoding is utf8mb4_general_ci. When attempting a SELECT query, the articles are not found in the database, but if I set the same content in the variable in the PHP editor, they are searched correctly. Do you have any idea how to fix this? Regards

<?php 
//from url json result
$title = 'G‐Eazy';
echo mb_detect_encoding($title)."\n\n"; //return: UTF-8 
//Not working
$query = "SELECT * FROM news WHERE title = '".$title."';";


$convert_title = mb_detect_encoding($title, 'UTF-8', 'ASCII');
echo $convert_title."\n"; //return: G?Eazy (- replace to ?)
echo mb_detect_encoding($convert_title)."\n\n"; //return: ASCII

//value set in editor php
$title = 'G-Eazy';
echo mb_detect_encoding($title)."\n\n"; //return: ASCII

//working
$query = "SELECT * FROM news WHERE title = '".$title."';";

?>

I tried to convert text using mb_convert_encoding function unfortunately I get errors. Below is my code with the result I get:

<?php

$title = 'G‐Eazy';
echo mb_detect_encoding($title)."\n\n"; //return: UTF-8
$convert_title = mb_convert_encoding($title, 'ASCII');
echo $convert_title."\n"; //return: G?Eazy (- replace to ?)
echo mb_detect_encoding($convert_title)."\n\n"; //return: ASCII



?>
urbciech
  • 1
  • 1
  • 1

0 Answers0