In java, when connecting to mysql db, I need to set like useUnicode=true&characterEncoding=UTF8 in the connection string:
Code: Select all
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://mydb.com/mydb?user=mydb&password=mydb&useUnicode=true&characterEncoding=UTF8");Code: Select all
class DBConnection {
private $con = null;
private $connection_string = 'mysql:host=localhost;dbname=mydb';
private $username = 'mydb';
private $password = 'mydb';
function __construct() {
try {
$this->con = new PDO($this->connection_string, $this->username, $this->password);
$this->con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
error_log($e->getMessage());
}
}
public function getConnection(){
return $this->con;
}
function closeConnection(){
$this->con = null;
}
}regards,
Mark