Połączenie PDO mysql: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
m |
|||
Linia 25: | Linia 25: | ||
$dbh->query($sql_set_utf); | $dbh->query($sql_set_utf); | ||
$sql_set_utf = "SET NAMES utf8"; | |||
$dbh->query($sql_set_utf); | |||
mb_internal_encoding( 'UTF-8' ); | mb_internal_encoding( 'UTF-8' ); |
Wersja z 00:47, 2 lip 2012
<source lang="php"> <?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' ); ?> </source>