LoginSignup
2
0

More than 3 years have passed since last update.

PHPが入っているサーバからmysqlに接続確認するためのスクリプト

Last updated at Posted at 2019-05-18

PHPが入っているサーバから、mysqlが入っているDBサーバに疎通確認したいなって時に、
実行するPHPスクリプトを作成してみました。

CA証明書は無ければoptions定義の行コメントアウトして、PDOのoptionsを削除して下さい。
dsn,user,pass,optionsは環境に合わせてください。

ただ単にshow databasesを実行してます。

#!/bin/php
<?php

$dbhost = 'xxx.xxx.xxx.xxx';
$dbname = 'sampledb';
$dsn = 'mysql:host='.$dbhost;
$user = 'app_admin';
$pass = 'password';
$options = array(
 PDO::MYSQL_ATTR_SSL_CA => '/usr/local/etc/ssl/mysql_ca-cert.pem' // CA証明書の指定
);

$client = new PDO($dsn,$user,$pass,$options);

$sql = "SHOW DATABASES";
$result = $client->query($sql);

foreach($result as $row) {
 var_dump($row);
}
?>
2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0