LoginSignup
0
0

More than 5 years have passed since last update.

PDOでDB接続メモ

Last updated at Posted at 2018-09-24

PDOでDBに接続する時の定型文

決まった形なので覚えること。

qiita.rb
$dsn = 'mysql:host=サーバー名;dbname=DB名;charset=文字コード';
$user = 'ユーザー名';
$password = 'パスワード';

try{
    $db = new PDO($dsn, $user, $password);
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch (PDOException $e){
    die('DB接続失敗'.$e->getMessage());
}
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