Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * The following function will create a PDO connection form PHP.
- * It sovles the issue of inserting the Unicode Characters.
- */
- function connect_db() {
- $servername = "localhost";
- $db_username = "root";
- $db_password = "root";
- $db_name = "DATABASE_NAME";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$db_name;charset=utf8", $db_username, $db_password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- $conn->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAME'utf8'");
- echo "\nPDO connection object created\n";
- return $conn;
- } catch (PDOException $e) {
- echo "Error: " . $e->getMessage();
- }
- }
Add Comment
Please, Sign In to add comment