SHARE
TWEET

Untitled

a guest Jun 30th, 2018 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. * The following function will create a PDO connection form PHP.
  4. * It sovles the issue of inserting the Unicode Characters.
  5. */
  6.  
  7. function connect_db() {
  8.     $servername = "localhost";
  9.     $db_username = "root";
  10.     $db_password = "root";
  11.     $db_name = "DATABASE_NAME";
  12.  
  13.     try {
  14.         $conn = new PDO("mysql:host=$servername;dbname=$db_name;charset=utf8", $db_username, $db_password);
  15.         // set the PDO error mode to exception
  16.         $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  17.         $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  18.         $conn->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAME'utf8'");
  19.  
  20.         echo "\nPDO connection object created\n";
  21.  
  22.         return $conn;
  23.     } catch (PDOException $e) {
  24.         echo "Error: " . $e->getMessage();
  25.     }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top