0

the config php file.

define("DB_SERVER", 'localhost'); define("DB_USER", 'root'); define("DB_PASS", 'pass'); define("DB_NAME", 'db'); define("mysql_query", 'SET CHARACTER_SET utf8'); 

here is the table structure as the table is been set to utf8_persian_ci, when i insert data from phpmyadmin it's working fine the arabic text gets insert.

+-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(111) | NO | PRI | NULL | auto_increment | | name | varchar(122) | NO | | NULL | | 

+-------+--------------+------+-----+---------+----------------+

the query function is kinda like bellow.

////quering public function query($sql){ $this->last_query = $sql; $result = mysql_query($sql, $this->connection); $this->confirm_query($result); return $result; } 

but here when i fetch the data from database i get the (?????) type of text. if insert from php input from, when i check the database its (شیبشبشب شبشبش) type of data but when i echo it back from php it show correct but in database the format has changed.

1- if insert from phpmyadmin data to database works fine(means the database character is ok) but can echo back with php (?????)

2- if insert by php from... in database (شیبشبشب شبشبش) but in echo back ok

how i can set the insert form to insert arabic text as is to database(mysql)

how i can echo it back as the data format is in database?

3
  • What is the charset output of the page? Commented May 24, 2014 at 19:58
  • local character from page is fine, but when it echo from database not fine Commented May 25, 2014 at 4:41
  • 1. switch from old mysql_.. api to the newer and supported PDO style (php.net/manual/en/book.pdo.php) 2. make sure you initialize your connection's character set correctly (php.net/manual/en/pdo.construct.php) 3. there are some duplicate SO questions about "PHP PDO MySql utf8" (e.g. stackoverflow.com/questions/4854446/…). 4. once you get the utf8 right there should be no more problems (e.g. right-to-left direction should not matter) Commented May 25, 2014 at 16:42

1 Answer 1

1

we have to set utf8 in connection.php with provides database connection for all:

<?php class Database { protected $host='localhost'; protected $user='root'; protected $db = 'db_test'; protected $pass = ''; protected $conn; public function __construct(){ $this->conn = new PDO("mysql:host=".$this->host.";dbname=".$this->db,$this->user,$this->pass); $this->conn->exec("SET CHARACTER SET utf8"); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.