Skip to content

Instantly share code, notes, and snippets.

@taitokiss
Last active November 2, 2018 01:23
Show Gist options
  • Save taitokiss/95bd7c359da03e3814b71e21b8bae34d to your computer and use it in GitHub Desktop.
Save taitokiss/95bd7c359da03e3814b71e21b8bae34d to your computer and use it in GitHub Desktop.
PHPでテスト用のデータベースにアクセスする
<?php
$dsn = 'mysql:dbname=idle;host=localhost';
$user = 'idlemaster';
$password = 'idlepass';
print('MySQLへの接続テスト'.'<br />');
try{
$dbh = new PDO($dsn, $user, $password);
$sql = 'select * from idlename';
foreach ($dbh->query($sql) as $row) {
print($row['id'].'->');
print($row['name']);
print('<br />');
}
}catch (PDOException $e){
print('Error:'.$e->getMessage());
die();
}
$dbh = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment