Last active
November 2, 2018 01:23
-
-
Save taitokiss/95bd7c359da03e3814b71e21b8bae34d to your computer and use it in GitHub Desktop.
PHPでテスト用のデータベースにアクセスする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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