0
4

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 5 years have passed since last update.

PHPでMySQL接続

Last updated at Posted at 2018-09-03
setAttribute(PDO::ATTR_EMULATE_PREPARES,false); $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); // echo "データベースに接続しました。"; return $pdo; }catch (PDOException $e){ echo 'DB接続においてエラーがありました。
'; echo $e->getMessage(); die(); } } ?>

pdoを利用したMySQL接続コードは上記です。functionを利用しているので「return $pdo」を使っている。

別のphpスクリプトが上記を流用する場合下記のコードでOK
require_once("dbconnect_function.php");
$dbh = db_connect();

使い終わったら $dbh=nullをわすれずに

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?