Połączenie PDO mysql

Z Podręcznik Administratora by OPZ SGU
Skocz do: nawigacja, szukaj
<?php
/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'login';

/*** mysql password ***/
$password = 'haslo';

//baza danych
$database='nazwabazydanych';

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
    /*** echo a message saying we have connected ***/
    //echo 'Connected to database';
    }
catch(PDOException $e)
    {
    exit ($e->getMessage());
    }
$sql_set_utf = "SET CHARSET utf8";
$dbh->query($sql_set_utf);

 $sql_set_utf = "SET NAMES utf8";
$dbh->query($sql_set_utf);

mb_internal_encoding( 'UTF-8' );
?>