2
3

More than 3 years have passed since last update.

PHPでのMySQL (データベース)接続 PDO

Last updated at Posted at 2020-04-30

PDOとは

PHP Data Objectsrの略称
PHPからデータベースのアクセスを抽象的にしてくれるもの

PHPからMySQLに接続するコード例(SELECT文)


<?php

$mysql    = 'mysql:host=localhost;dbname=xxxxxx,charet=utf8';
//xxxxxx === 自分のmysql中の接続したいデータベース名
$user     = 'xxxxxx'; 
//xxxxxx === 自分のmysqlユーザー名
$passwoad = 'xxxxxx'; 
//xxxxxx === 自分のmysqlパスワード

try {
    $db     = new PDO($mysql, $user, $passwoad);
    $select = "SELECT * FROM" ;
    $res    = $db->query($select);

} catch (PDOException $e) {
    echo '接続エラー: ' . $e->getMessage();
}

?>
2
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
2
3