PHPでPDOを使ってMySQLに接続するサンプル

phpコード:
$dsn = 'mysql:dbname=ent;host=172.17.20.100′;
$user = 'root’;
$password = 'jz345pwd′;
try {
$dbh = new pdo($dsn, $user, $password, array(pdo::attr_persistent => true));
$dbh->query('set names utf8;’);
foreach ($dbh->query('select * from yutbl’) as $row) {
print_r($row);
}
} catch (pdoexception $e) {
echo 'connection failed: ' . $e->getmessage();
}

PHP

Posted by arkgame