Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Accessing MySQL from PHP
Search
LucienLee
July 09, 2013
Programming
380
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Accessing MySQL from PHP
Fundamental PHP & Web Development
LucienLee
July 09, 2013
More Decks by LucienLee
See All by LucienLee
SASS & Compass 101
lucienlee
1
320
Use PaaS service to host your web - with pagodabox
lucienlee
0
88
final album
lucienlee
0
79
Simple Album
lucienlee
0
110
DataBase and MySQL
lucienlee
1
240
PHP 101+1:function & form
lucienlee
1
300
PHP 101: flow control
lucienlee
0
340
Start to Build your Web
lucienlee
1
440
既然如此,那我們來hack資本世界吧!
lucienlee
0
170
Other Decks in Programming
See All in Programming
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
400
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
100
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
730
iOSDC2026登壇資料.pdf
riofujimon
0
200
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
270
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
160
Heart of Swift Concurrency
koher
0
1.1k
AHC070解法紹介
eijirou
0
140
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
320
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
9.2k
Featured
See All Featured
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
730
GraphQLとの向き合い方2022年版
quramy
50
15k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
480
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
340
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
340
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Transcript
Accessing MySQL from PHP Fundamental PHP & Web Development lecturer
: Lucien Lee 李柏緯 Lecture 5
2
flow •Connect MySQL Server •Open database •execute SQL •close database
3
connect server 4 Before we can access data in a
database, we must open a connection to the MySQL server.
5
6 mysql_connect mysql_connect(host,username,password); mysql_connect(localhost,‘root’,‘123456’);
SELECT DB choose the db you would like to query
7
8
9 mysql_select_db $link = mysql_connect(localhost,‘root’,‘123456’); mysql_select_db(‘user’, $link);
query execute SQL query BY PHP 10
11
12 mysql_query $sql = “SELECT * FROM table”; $result =
mysql_query($sql,$link);
PHP 5 and older //before query mysql_query('SET NAMES utf8'); 13
fetch result after query, we only get pointer to resource
14
mysql_fetch_array while($row = mysql_fetch_array($result)){ //do something echo $row[‘fieldName’]; echo $row[0];
} 15
mysql_fetch_array while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { //do something echo $row[‘fieldName’]; //echo
$row[0] is wrong } 16
mysql_fetch_assoc while($row = mysql_fetch_assoc($result)) { //do something echo $row[‘fieldName’]; }
17
mysql_fetch_array while($row = mysql_fetch_array($result, MYSQL_NUM)) { //do something //echo $row[‘fieldName’]
is wrong echo $row[0]; } 18
array type •MYSQL_ASSOC •MYSQL_NUM •MYSQL_BOTH 19
remove your pointer we may directly get a specific record
20
mysql_data_seek mysql_data_seek(data,row_num) $row = mysql_fetch_array($result); mysql_data_seek($result,8) $row = mysql_fetch_array($result); //get
9th record 21
mysql_close close Database connect 22
mysql_close mysql_close(resource); 23
more something else 24
mysql_num_rows 25 KNOW HOw many rows selected
mysql_num_rows mysql_num_rows($result); 26
mysql_affected_rows know how many record affected 27
mysql_affected_rows //after update mysql_affected_rows($link_identifier); 28
mysql_fetch_field get field information 29
mysql_fetch_field mysql_fetch_field(data,offset) $meta= mysql_fetch_field($result,1); echo $meta->name; echo $meta->type; 30
? Use SQL to manipulate record 31
INSERT •Insert a new record • INSERT INTO `tableName` (field1,field2,...)
Values (data1,data2...) 32
UPdate •update an exist record •UPDATE `tableName` SET field =
data, ... WHERE condition 33
DELETE •delete an exist record •DELETE FROM `table` WHERE condition
34
You can use better way 35
mysqli 36 mysql improvement
reference 37 http://www.w3schools.com/php/php_ref_mysqli.asp
practice 38 • Make a message board that users can
leave a message containing name(necessary), message and timestamp. • users can view all message and delete them.