{"id":810,"date":"2012-05-03T04:33:18","date_gmt":"2012-05-03T04:33:18","guid":{"rendered":"http:\/\/brain.dailyon.net\/?p=810"},"modified":"2012-05-03T04:33:18","modified_gmt":"2012-05-03T04:33:18","slug":"php-pdophp-data-objects-extension-%ec%9d%b4%eb%9e%80","status":"publish","type":"post","link":"https:\/\/blog.goorigo.com\/?p=810","title":{"rendered":"PHP : PDO(PHP Data Objects extension) \uc774\ub780?"},"content":{"rendered":"<div>PDO\ub294?<strong>PHP Data Objects<\/strong>?extension\uc758 \uc57d\uc790\ub85c PHP\uc5d0\uc11c \ub370\uc774\ud130\ubca0\uc774\uc2a4\ub97c \uc0ac\uc6a9\ud558\ub824\uace0 \ud560 \ub54c \uc0ac\uc6a9\ud558\ub294 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc774\ub2e4.<\/div>\n<div><\/div>\n<div>\uac00\ubccd\uace0, \uae54\ub054\ud55c \ucf54\ub529\uc744 \uac00\ub2a5\ud558\uac8c \ud574\uc900 \ub2e4\ub294 \uc810\uc5d0\uc11c \uac1c\ubc1c\uc790\ub4e4\uc5d0\uac8c \ud544\uc694\ud55c \ub77c\uc774\ube0c\ub7ec\ub9ac\ub77c\uace0 \ud560 \uc218 \uc788\uc744 \uac83 \uac19\ub2e4.<\/div>\n<div>\ub610, PHP + MySQL \uc870\ud569 \ubfd0\ub9cc \uc544\ub2c8\ub77c Oracle, SQLite \ub4f1 \uac70\uc758 \ubaa8\ub4e0 DBMS\uc640 \uc77c\uad00\uc131\uc788\ub294 \uc778\ud130\ud398\uc774\uc2a4\ub85c \uc811\uadfc\uc774 \uac00\ub2a5\ud558\uae30 \ub54c\ubb38\uc5d0 \ucd94\ud6c4 \uc774\uc2dd\uc131\uc774 \uc88b\ub2e4\ub294 \uc7a5\uc810\ub3c4 \uc788\ub2e4.<\/div>\n<div><\/div>\n<div>\ub300\uc2e0, \uac1d\uccb4\uc9c0\ud5a5(Object-Oriented)\uc73c\ub85c \ub418\uc5b4\uc788\uae30 \ub54c\ubb38\uc5d0 \uc544\ubb34\ub798\ub3c4 mysqli \uac19\uc740 DB extension \ud568\uc218\ub4e4 \ubcf4\ub2e4\ub294 \ubd80\ud558\uac00 \ud06c\ub2e4.<\/div>\n<div><\/div>\n<div>PDO\ub294 PHP 5.1\ubd80\ud130 \uc9c0\uc6d0\ud558\uace0, 5.0\uc5d0\uc11c\ub294 PECL extension\uc744 \ud1b5\ud574 \uac00\ub2a5\ud558\ub2e4\uace0 \ud55c\ub2e4.<\/div>\n<div>\uc124\uce58\uac00 \ub418\uc9c0 \uc54a\uc740 \ud658\uacbd\uc5d0\uc11c\uc758 \uc2dc\uc791\uc740 \uc544\ub798 PHP \ub9e4\ub274\uc5bc \ub9c1\ud06c\ub97c \ucc38\uc870\ud558\uae38 \ubc14\ub780\ub2e4.<\/div>\n<div><\/div>\n<div><a href=\"http:\/\/www.php.net\/manual\/kr\/book.pdo.php\" target=\"_blank\">http:\/\/www.php.net\/manual\/kr\/book.pdo.php<\/a><\/div>\n<div><\/div>\n<div><\/div>\n<div>PDO\uac00 \ub9cc\ub4e4\uc5b4\uc9c0\uac8c \ub41c \uacc4\uae30, PDO\uc758 \uac1c\ub150\ub4f1\uc744 \ud30c\uc545\ud558\ub294\ub370 \ub3c4\uc6c0\uc774 \ub418\ub294 \uae00\uc774 \uc788\uc5b4\uc11c \ub9c1\ud06c\ud55c\ub2e4.<\/div>\n<div><\/div>\n<div>PHP 5 Data Object (PDO) Abstraction Layer\uc640 \uc624\ub77c\ud074<\/div>\n<div><a href=\"http:\/\/www.oracle.com\/technology\/global\/kr\/pub\/articles\/php_experts\/otn_pdo_oracle5.html\" target=\"_blank\">http:\/\/www.oracle.com\/technology\/global\/kr\/pub\/articles\/php_experts\/otn_pdo_oracle5.html<\/a><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div>PHP \ub9e4\ub274\uc5bc\uc5d0\uc11c \ubc1c\ucdcc\ud55c \uc608\uc81c\ub85c \uc0ac\uc6a9\ubc95\uc744 \uc54c\uc544\ubcf8\ub2e4.<\/div>\n<div><\/div>\n<div>\n<div>\n<div><a href=\"http:\/\/docs.cena.co.kr\/textyle\/11910#\">?<\/a><\/div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;?php<\/code><\/div>\n<div><code>$dbh<\/code> <code>= <\/code><code>new<\/code> <code>PDO(<\/code><code>'odbc:sample'<\/code><code>, <\/code><code>'db2inst1'<\/code><code>, <\/code><code>'ibmdb2'<\/code><code>);<\/code><\/div>\n<div><\/div>\n<div><code>\/* Delete all rows from the FRUIT table *\/<\/code><\/div>\n<div><code>$count<\/code> <code>= <\/code><code>$dbh<\/code><code>-&gt;<\/code><code>exec<\/code><code>(<\/code><code>\"DELETE FROM fruit WHERE colour = 'red'\"<\/code><code>);<\/code><\/div>\n<div><\/div>\n<div><code>\/* Return number of rows that were deleted *\/<\/code><\/div>\n<div><code>print<\/code><code>(<\/code><code>\"Deleted $count rows.n\"<\/code><code>);<\/code><\/div>\n<div><code>?&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div><\/div>\n<div>\uac1d\uccb4\ub97c \uc0dd\uc131\ud558\ub294 \ubc29\uc2dd\uc73c\ub85c \uc5f0\uacb0 \ud6c4, \uac04\ub2e8\ud55c query\ub97c \ub0a0\ub824 \uacb0\uacfc\ub97c \uc5bb\ub294 \uc608\uc81c. exec \uba54\uc11c\ub4dc\uac00 \uc801\uc6a9\ub41c \uc5f4 \uac1c\uc218\ub97c \ub9ac\ud134\ud558\ub294\uac8c \ud765\ubbf8\ub86d\ub2e4.<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\n<div><a href=\"http:\/\/docs.cena.co.kr\/textyle\/11910#\">?<\/a><\/div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<div>10<\/div>\n<div>11<\/div>\n<div>12<\/div>\n<div>13<\/div>\n<div>14<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;?php<\/code><\/div>\n<div><code>\/* Begin a transaction, turning off autocommit *\/<\/code><\/div>\n<div><code>$dbh<\/code><code>-&gt;beginTransaction();<\/code><\/div>\n<div><\/div>\n<div><code>\/* Change the database schema and data *\/<\/code><\/div>\n<div><code>$sth<\/code> <code>= <\/code><code>$dbh<\/code><code>-&gt;<\/code><code>exec<\/code><code>(<\/code><code>\"DROP TABLE fruit\"<\/code><code>);<\/code><\/div>\n<div><code>$sth<\/code> <code>= <\/code><code>$dbh<\/code><code>-&gt;<\/code><code>exec<\/code><code>(\"UPDATE dessert<\/code><\/div>\n<div><code>????<\/code><code>SET name = <\/code><code>'hamburger'<\/code><code>\");<\/code><\/div>\n<div><\/div>\n<div><code>\/* Recognize mistake and roll back changes *\/<\/code><\/div>\n<div><code>$dbh<\/code><code>-&gt;rollBack();<\/code><\/div>\n<div><\/div>\n<div><code>\/* Database connection is now back in autocommit mode *\/<\/code><\/div>\n<div><code>?&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div><\/div>\n<div>\ud2b8\ub79c\uc7ad\uc158\ub3c4 \ub41c\ub2e4.<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\n<div>\n<div><a href=\"http:\/\/docs.cena.co.kr\/textyle\/11910#\">?<\/a><\/div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<div>10<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;?php<\/code><\/div>\n<div><code>function<\/code> <code>getFruit(<\/code><code>$conn<\/code><code>) {<\/code><\/div>\n<div><code>????<\/code><code>$sql<\/code> <code>= <\/code><code>'SELECT name, colour, calories FROM fruit ORDER BY name'<\/code><code>;<\/code><\/div>\n<div><code>????<\/code><code>foreach<\/code> <code>(<\/code><code>$conn<\/code><code>-&gt;query(<\/code><code>$sql<\/code><code>) <\/code><code>as<\/code> <code>$row<\/code><code>) {<\/code><\/div>\n<div><code>????????<\/code><code>print<\/code> <code>$row<\/code><code>[<\/code><code>'NAME'<\/code><code>] . <\/code><code>\"t\"<\/code><code>;<\/code><\/div>\n<div><code>????????<\/code><code>print<\/code> <code>$row<\/code><code>[<\/code><code>'COLOUR'<\/code><code>] . <\/code><code>\"t\"<\/code><code>;<\/code><\/div>\n<div><code>????????<\/code><code>print<\/code> <code>$row<\/code><code>[<\/code><code>'CALORIES'<\/code><code>] . <\/code><code>\"n\"<\/code><code>;<\/code><\/div>\n<div><code>????<\/code><code>}<\/code><\/div>\n<div><code>}<\/code><\/div>\n<div><code>?&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>prepare\ub85c \ubc18\ubcf5\ub418\ub294 \ucffc\ub9ac\uc5d0 \ub300\ud55c \uba54\ubaa8\ub9ac\ub97c \uc808\uc57d\ud558\uace0, SQL \uc778\uc81d\uc158\uc744 \ubc29\uc9c0\ud560 \uc218 \uc788\ub2e4.<\/p>\n<\/div>\n<div>\uac1c\uc778\uc801\uc73c\ub85c\ub3c4, \uc774\ub7f0 \ubc29\ubc95\uc774 \uc788\ub2e4\ub294 \uac83\uc740 \uc54c\uc558\uc9c0\ub9cc \uae30\uc874\uc5d0 SQL\ubb38\uc744 \ubb38\uc790\uc5f4\ub85c \uc0dd\uc131\ud574\uc11c \uc0ac\uc6a9\ud558\ub358 \ubc29\uc2dd\uc744 \uc27d\uac8c \ubc84\ub9ac\uc9c0 \ubabb\ud558\uace0 \uc788\uc5c8\ub294\ub370, \uadf8\ub7f0 \uace0\uc815 \uad00\ub150\uc5d0\uc11c \ud0c8\ud53c\ud574\uc57c \uaca0\ub2e4.<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\n<div>\n<div><a href=\"http:\/\/docs.cena.co.kr\/textyle\/11910#\">?<\/a><\/div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<div>10<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;?php<\/code><\/div>\n<div><code>function<\/code> <code>getFruit(<\/code><code>$conn<\/code><code>) {<\/code><\/div>\n<div><code>????<\/code><code>$sql<\/code> <code>= <\/code><code>'SELECT name, colour, calories FROM fruit ORDER BY name'<\/code><code>;<\/code><\/div>\n<div><code>????<\/code><code>foreach<\/code> <code>(<\/code><code>$conn<\/code><code>-&gt;query(<\/code><code>$sql<\/code><code>) <\/code><code>as<\/code> <code>$row<\/code><code>) {<\/code><\/div>\n<div><code>????????<\/code><code>print<\/code> <code>$row<\/code><code>[<\/code><code>'NAME'<\/code><code>] . <\/code><code>\"t\"<\/code><code>;<\/code><\/div>\n<div><code>????????<\/code><code>print<\/code> <code>$row<\/code><code>[<\/code><code>'COLOUR'<\/code><code>] . <\/code><code>\"t\"<\/code><code>;<\/code><\/div>\n<div><code>????????<\/code><code>print<\/code> <code>$row<\/code><code>[<\/code><code>'CALORIES'<\/code><code>] . <\/code><code>\"n\"<\/code><code>;<\/code><\/div>\n<div><code>????<\/code><code>}<\/code><\/div>\n<div><code>}<\/code><\/div>\n<div><code>?&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>SELECT\ub85c \uac12\uc744 \uac00\uc838\uc624\ub294 \uc608\uc81c.<\/p>\n<\/div>\n<div>\uc548\ub3cc\uc544 \uac08 \uac83 \uac19\uc740 \ucf54\ub4dc\uc778\ub370 \ub098\uc640\uc788\ub2e4. \uc2e0\uae30\ud558\ub2e4.<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\n<div>\n<div><a href=\"http:\/\/docs.cena.co.kr\/textyle\/11910#\">?<\/a><\/div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<div>10<\/div>\n<div>11<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;?php<\/code><\/div>\n<div><code>\/* Execute a prepared statement by binding PHP variables *\/<\/code><\/div>\n<div><code>$calories<\/code> <code>= 150;<\/code><\/div>\n<div><code>$colour<\/code> <code>= <\/code><code>'red'<\/code><code>;<\/code><\/div>\n<div><code>$sth<\/code> <code>= <\/code><code>$dbh<\/code><code>-&gt;prepare('SELECT name, colour, calories<\/code><\/div>\n<div><code>????<\/code><code>FROM fruit<\/code><\/div>\n<div><code>????<\/code><code>WHERE calories &lt; :calories AND colour = :colour');<\/code><\/div>\n<div><code>$sth<\/code><code>-&gt;bindParam(<\/code><code>':calories'<\/code><code>, <\/code><code>$calories<\/code><code>, PDO::PARAM_INT);<\/code><\/div>\n<div><code>$sth<\/code><code>-&gt;bindParam(<\/code><code>':colour'<\/code><code>, <\/code><code>$colour<\/code><code>, PDO::PARAM_STR, 12);<\/code><\/div>\n<div><code>$sth<\/code><code>-&gt;execute();<\/code><\/div>\n<div><code>?&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>prepared \ub41c SELECT \ucffc\ub9ac\uc5d0 WHERE \uc870\uac74\uc744 bind \ud574\uc11c \uc2e4\ud589\ud558\ub294 \uc608\uc81c.<\/p>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\n<div>\n<div><a href=\"http:\/\/docs.cena.co.kr\/textyle\/11910#\">?<\/a><\/div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<div>10<\/div>\n<div>11<\/div>\n<\/td>\n<td>\n<div>\n<div><code>&lt;?php<\/code><\/div>\n<div><code>$sth<\/code> <code>= <\/code><code>$dbh<\/code><code>-&gt;prepare(<\/code><code>\"SELECT name, colour FROM fruit\"<\/code><code>);<\/code><\/div>\n<div><code>$sth<\/code><code>-&gt;execute();<\/code><\/div>\n<div><\/div>\n<div><code>\/* Exercise PDOStatement::fetch styles *\/<\/code><\/div>\n<div><code>print<\/code><code>(<\/code><code>\"PDO::FETCH_ASSOC: \"<\/code><code>);<\/code><\/div>\n<div><code>print<\/code><code>(<\/code><code>\"Return next row as an array indexed by column namen\"<\/code><code>);<\/code><\/div>\n<div><code>$result<\/code> <code>= <\/code><code>$sth<\/code><code>-&gt;fetch(PDO::FETCH_ASSOC);<\/code><\/div>\n<div><code>print_r(<\/code><code>$result<\/code><code>);<\/code><\/div>\n<div><code>print<\/code><code>(<\/code><code>\"n\"<\/code><code>);<\/code><\/div>\n<div><code>?&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>ASSOCiated (\ubc30\uc5f4)\ub85c \uacb0\uacfc\ub97c \uac00\uc838\uc624\ub294 \uc608\uc81c.<\/p>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div>PDO\uc5d0 \ub300\ud55c \uac1c\ub150 \uc870\ucc28 \ud76c\ubc15\ud55c \uc0c1\ud669\uc5d0\uc11c \uc815\ubcf4\ub97c \uc5bb\uc73c\ub824\ub294\ub370 \uc758\uc678\ub85c \uc790\ub8cc\uac00 \ub9ce\uc774 \uc5c6\ub294 \uac83\uc744 \uc54c\uc558\ub2e4. \uc774 \uae00\uc758 \ub0b4\uc6a9\ub3c4 \uc544\uc8fc \uc791\uc740 \ubd80\ubd84\ub9cc\uc744 \uc124\uba85\ud558\uace0 \uc788\uc9c0\ub9cc, \ub2e4\ub978 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc5d0\uc11c \uc774\ubbf8 \ub300\uc138\uac00 \ub410\ub2e4\uace0 \ud310\ub2e8\ub418\ub294 PDO\ub85c \uac08\uc544\ud0c0\ub294\ub370 \uc870\uae08\uc774\ub098\ub9c8 \ub3c4\uc6c0\uc774 \ub418\uc5c8\uc73c\uba74 \uc88b\uaca0\ub2e4.<\/div>\n<div><\/div>\n<div>\ub354 \uc790\uc138\ud55c \uc0ac\uc6a9\ubc95\uc740 RFTM! (Read the Fucking Manual)<\/div>\n<div><\/div>\n<div>\ucd9c\ucc98 \ud83d\ude15<a href=\"http:\/\/docs.cena.co.kr\/\">http:\/\/docs.cena.co.kr\/<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>PDO\ub294?PHP Data Objects?extension\uc758 \uc57d\uc790\ub85c PHP\uc5d0\uc11c \ub370\uc774\ud130\ubca0\uc774\uc2a4\ub97c \uc0ac\uc6a9\ud558\ub824\uace0 \ud560 \ub54c \uc0ac\uc6a9\ud558\ub294 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc774\ub2e4. \uac00\ubccd\uace0, \uae54\ub054\ud55c \ucf54\ub529\uc744 \uac00\ub2a5\ud558\uac8c \ud574\uc900 \ub2e4\ub294 \uc810\uc5d0\uc11c \uac1c\ubc1c\uc790\ub4e4\uc5d0\uac8c \ud544\uc694\ud55c \ub77c\uc774\ube0c\ub7ec\ub9ac\ub77c\uace0 \ud560 \uc218 \uc788\uc744 \uac83 \uac19\ub2e4. \ub610, PHP + MySQL&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts\/810"}],"collection":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=810"}],"version-history":[{"count":0,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts\/810\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}