Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHPとDBの常識的な話
Search
らいあ
February 19, 2017
Programming
0
140
PHPとDBの常識的な話
らいあ
February 19, 2017
Tweet
Share
More Decks by らいあ
See All by らいあ
GoのDBライブラリについて調べてみた
ryer
0
580
shimanego3-lt.pdf
ryer
0
400
PageSpeed基礎知識
ryer
0
60
PHPひとめぐり
ryer
0
38
関西ソーシャルゲーム勉強会のご紹介
ryer
0
51
Other Decks in Programming
See All in Programming
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
210
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
260
Create a website using Spatial Web
akkeylab
0
310
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
Select API from Kotlin Coroutine
jmatsu
1
210
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
270
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
250
童醫院敏捷轉型的實踐經驗
cclai999
0
210
#QiitaBash MCPのセキュリティ
ryosukedtomita
0
670
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
20
3.8k
関数型まつりレポート for JuliaTokai #22
antimon2
0
160
RailsGirls IZUMO スポンサーLT
16bitidol
0
130
Featured
See All Featured
Code Review Best Practice
trishagee
69
18k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
500
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
The Pragmatic Product Professional
lauravandoore
35
6.7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Typedesign – Prime Four
hannesfritz
42
2.7k
Making Projects Easy
brettharned
116
6.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Transcript
None
None
None
None
None
None
None
None
None
# yum install php-pdo
$DSN = ‘mysql:host=10.0.0.1;dbname=userdb’; $OPT = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]; $pdo =
new PDO($DSN, $USER, $PASSWD, $OPT);
$DSN = ‘mysql:host=10.0.0.1;dbname=userdb’;
$OPT = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
$cnt = $pdo->exec(“INSERT INTO prefs (id, pref) VALUES (1, ’沖縄県')");
$stmt = $pdo->query("SELECT * FROM prefs"); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); var_dump($rows);
$cnt = $pdo->exec(更新SQL) $stmt = $pdo->query(選択SQL)
$rows = $stmt->fetchAll();
$pdo->beginTransaction(); try { ... $pdo->commit(); } catch (Exception $ex) {
... $pdo->rollBack(); }
簡単 でしょ?
None
None
None
None
$DSN = “mysql:dbname=db1;charset=sjis”; $DSN = “pgsql:dbname=db1; options=‘--client_encoding=sjis’”;
None
忘れずに
None
$sql = “SELECT * FROM prefs WHERE id =:id”; $stmt
= $pdo->prepare($sql); $stmt->execute([‘id’ => 123]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); var_dump($rows);
$stmt = $pdo->prepare(プレースホルダ付SQL文) $stmt->execute(パラメータの配列)
None
None
None
$OPT = [PDO::ATTR_EMULATE_PREPARES => false];
常識?
None
None
None
// すべての記事をSELECT $sql = “SELECT * FROM kiji”; $stmt =
$pdo->query($sql); $rows = $stmt->fetchAll(); foreach ($rows as $kiji) { // 記事の本文を更新する関数 update($kiji[’id’], $kiji[‘body’]); }
// すべての記事をSELECT $sql = “SELECT * FROM kiji”; $stmt =
$pdo->query($sql); $rows = $stmt->fetchAll(); foreach ($stmt as $kiji) { // 記事の本文を更新する関数 update($kiji[’id’], $kiji[‘body’]); }
$ php update_kiji.php
$ php update_kiji.php PHP Fatal error: Allowed memory size of
134217728 bytes exhausted PHP Stack trace: PHP 1. update_kiji.php PHP 2. PDO->query()
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted
None
$OPT = [PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false];
PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2014 Cannot
execute queries while other unbuffered queries are active.
None
// すべての記事をSELECT ini_set(“memory_limit”, “1G”); $sql = “SELECT id FROM kiji”;
$stmt = $pdo->query($sql); foreach ($stmt as $kiji) { // 記事の本文をSELECTして更新する関数 update($kiji[’id’], $kiji[‘body’]); }
常識…?
None