$30 off During Our Annual Pro Sale. View Details »
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
600
shimanego3-lt.pdf
ryer
0
420
PageSpeed基礎知識
ryer
0
62
PHPひとめぐり
ryer
0
39
関西ソーシャルゲーム勉強会のご紹介
ryer
0
52
Other Decks in Programming
See All in Programming
非同期処理の迷宮を抜ける: 初学者がつまづく構造的な原因
pd1xx
1
740
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
2
220
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
400
Cell-Based Architecture
larchanjo
0
140
LT資料
t3tra
6
970
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
150
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
Developing static sites with Ruby
okuramasafumi
0
310
SwiftUIで本格音ゲー実装してみた
hypebeans
0
450
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
130
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.1k
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
370
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
0
1.9k
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
Producing Creativity
orderedlist
PRO
348
40k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Practical Orchestrator
shlominoach
190
11k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
0
160
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
0
210
Context Engineering - Making Every Token Count
addyosmani
9
540
Balancing Empowerment & Direction
lara
5
810
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
2
2.7k
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