mysql - php unable to read characters in utf8 -


i trying simple following:

<?php  header("content-type: text/html;charset=utf-8");  $con=mysqli_connect("localhost","dsdsds","test1234","dsdsds"); if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();   }   $result = mysqli_query($con,"select * discounts");  while($row = mysqli_fetch_array($result))   {   echo $row['name'] . " " . $row['rate'];   echo "<br>";   }     ?> 

when this, output shows ??????. in database table, showing arabic correctly. doing wrong? know should add code set mysqli utf8 , when do, breaks script.

  if (!$mysqli->set_charset("utf8")) {         printf("error loading character set utf8: %s\n", $mysqli->error);     } else {         printf("current character set: %s\n", $mysqli->character_set_name());     } 

looking forward support

mysqli has 2 ways call methods. procedural , object-oriented. you'll see in documentation both methods.

this procedural style:

$con=mysqli_connect... $result = mysqli_query... $row = mysqli_fetch_array... 

this oo style:

$mysqli = new mysqli("localhost"... $mysqli->set_charset("utf8") $result = $mysqli->query... $row = $mysqli->fetch_array... 

it looks mixing styles. change $mysqli->set_charset $mysqli_set_charset , try again.

if opinion, prefer oo style.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -