You’ll have it in your connection string like:
"mysql:host=$host;dbname=$db;charset=utf8mb4"
HOWEVER, prior to PHP 5.3.6, the charset option was ignored. If you’re running an older version of PHP, you must do it like this:
$dbh = new PDO("mysql:host=$host;dbname=$db", $user, $password);
$dbh->exec("set names utf8mb4");
Related Contents:
- Why shouldn’t I use mysql_* functions in PHP?
- PDOException SQLSTATE[HY000] [2002] No such file or directory
- PDOException “could not find driver”
- mysqli or PDO – what are the pros and cons? [closed]
- Row count with PDO
- PDO get the last ID inserted
- In PHP with PDO, how to check the final SQL parametrized query? [duplicate]
- Getting raw SQL query string from PDO prepared statements
- PDO MySQL: Use PDO::ATTR_EMULATE_PREPARES or not?
- What is the difference between MySQL, MySQLi and PDO? [closed]
- MySQL check if a table exists without throwing an exception
- How to apply bindValue method in LIMIT clause?
- Can I mix MySQL APIs in PHP?
- Why I am getting Cannot pass parameter 2 by reference error when I am using bindParam with a constant value?
- Installing PDO driver on MySQL Linux server
- PDO support for multiple queries (PDO_MYSQL, PDO_MYSQLND)
- Real escape string and PDO [duplicate]
- PDO mysql: How to know if insert was successful
- PHP – Using PDO with IN clause array
- How to properly set up a PDO connection
- How do I return integer and numeric columns from MySQL as integers and numerics in PHP?
- How can I properly use a PDO object for a parameterized SELECT query
- SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO [duplicate]
- PDO::PARAM for type decimal?
- How to view query error in PDO PHP
- PDO::PARAM for dates?
- What is the advantage of using try {} catch {} versus if {} else {}
- PDO binding values for MySQL IN statement [duplicate]
- PHP 7 RC3: How to install missing MySQL PDO
- PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused
- How to get numeric types from MySQL using PDO?
- PDO::fetchAll vs. PDO::fetch in a loop
- How to get a query error from prepare() in PDO PHP?
- PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
- How to bind parameters to a raw DB query in Laravel that’s used on a model?
- Do SQL connections opened with PDO in PHP have to be closed
- php artisan migrate throwing [PDO Exception] Could not find driver – Using Laravel
- Get query back from PDO prepared statement [duplicate]
- Why does PDO print my password when the connection fails?
- Checking for an empty result (PHP, PDO, and MySQL) [duplicate]
- Causes of MySQL error 2014 Cannot execute queries while other unbuffered queries are active
- Can I create a database using PDO in PHP?
- What is the PDO equivalent of function mysql_real_escape_string?
- How do I set ORDER BY params using prepared PDO statement?
- How to check if a row exists in MySQL? (i.e. check if username or email exists in MySQL)
- PDO: MySQL server has gone away
- SQL injection that gets around mysql_real_escape_string()
- Maximum execution time in phpMyadmin
- mysql server port number
- convert date string to mysql datetime field