Skip to content

Instantly share code, notes, and snippets.

@nnsnodnb
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save nnsnodnb/01ce4156d5499e476627 to your computer and use it in GitHub Desktop.

Select an option

Save nnsnodnb/01ce4156d5499e476627 to your computer and use it in GitHub Desktop.
PHPでMySQLとの接続テスト簡単コード
<?php
$dsn = 'mysql:dbname=mysql;host=127.0.0.1';
$user = 'root';
$password = 'PASSWORD';
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT COUNT(*) as cnt FROM user";
foreach ($dbh->query($sql) as $row)
{
echo $row['cnt'] ."\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment