Skip to content

Instantly share code, notes, and snippets.

@chihirokaasan
Created July 24, 2017 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chihirokaasan/718c23c0b8b4509dba1db8950037ce1d to your computer and use it in GitHub Desktop.
Save chihirokaasan/718c23c0b8b4509dba1db8950037ce1d to your computer and use it in GitHub Desktop.
PHPからMySQLへ繋ぐ際のサンプル
<?php
$dsn = 'mysql:host=172.17.0.2;dbname=your-database-name';
$username = 'root';
$password = 'your-root-password';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$dbh = new PDO($dsn, $username, $password, $options);
$sql = "SELECT * FROM Table";
$stmt = $dbh->query($sql);
var_dump($stmt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment