-1

Hey I tried a code that uses pdo with php and on the local wamp server it works perfectly and shows Hebrew and English but when I put the code on the web it shows me Hebrew as weird symbols like this ׳™׳—׳•׳“ ׳˜׳™׳™׳’׳¨׳™׳ ׳׳”׳ both the wamp sql table and the web sql table are set to utf8_general_ci

this is my code:

    <?php
    $db = new PDO('mysql:host=127.0.0.1;dbname=android;charset=utf8', 'root', '');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $db->query('SELECT * FROM sample');
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

$out = '';
if (is_array($results) && count($results) > 0) 
{
  foreach ($results as $sqlRow) 
  {
    $out .= $sqlRow['id']."|||".$sqlRow['name']."|||";
  }

  $out = substr($out, 0, -3);
}
echo $out;
?>
orisgoofo
  • 53
  • 1
  • 5
  • Did you try inserting directly into MySQL to ensure it's PHP the problem? – Magd Kudama Dec 11 '16 at 12:28
  • Answers from this post might help you: [MySQL db question marks instead of hebrew characters..?](http://stackoverflow.com/questions/5287821/mysql-db-question-marks-instead-of-hebrew-characters) – Alon Adler Dec 11 '16 at 12:32

2 Answers2

0

The problem is probably not in MySQL, but in PHP on your web server. Try setting this property in your php.ini:

default_charset = "utf-8"

Read more on this property here.

Yury Fedorov
  • 12,277
  • 6
  • 44
  • 63
0
change to this row
for me it is helped
This after you set the table utf-8

$conn = new PDO("mysql:host=localhost; dbname=$database;charset=UTF8","root","",array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"))or die("no connction"); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

uriya harel
  • 73
  • 1
  • 4