LoginSignup
4
3

More than 5 years have passed since last update.

php pdo MySQL MariaDBに接続

Last updated at Posted at 2018-02-13

phpのpdoでmariadb(mysql)に接続

私は、これでできました。

login.php
<?php
    define('DB_HOST', 'localhost');
    define('DB_USER', 'ユーザー');
    define('DB_PASSWORD', 'DBパスワード');
    define('DB_NAME', 'DBの名前');

    // エラー表示設定:通知系以外全て表示    
    error_reporting(E_ALL & ~E_NOTICE);

    try {
        $dbh = new PDO('mysql:'.DB_NAME.';'.DB_HOST, DB_USER, DB_PASSWORD);
        print('接続しました。');
    }
    catch(PDOException $e){
        print('ERROR:'.$e->getMessage());
        exit;
    }
?>
4
3
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
4
3