0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHPでMDB2の接続確認をする

Posted at

MDB2の接続周りを確認した時のメモ。

動作確認用のコード
<?php
// MDB2の読み込み
require_once 'MDB2.php';

// DNSを定義
$dns = 'mysql://ユーザー:パスワード@ホスト:ポート/DB?charset=utf8';

// DBへ接続
$db = MDB2::connect($dns);

// 接続結果の確認
if(MDB2::isError($db)) {
    echo "NG:" . $db->getMessage() . "\n";
    exit;
} else {
    echo "OK\n";
}

// SQLを実行
$query = 'select * from hoge limit 5';
$q = $db->query($query);

// 実行結果を出力
while($row = $q->fetchRow()) {
  var_dump($row);
}
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?