본문 바로가기
IT/PHP

[PHP] PDO API

by Spring Up!! 2016. 10. 22.
반응형

자세한 정보는 http://php.net/manual/kr/book.pdo.php

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.

PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0; PDO requires the new OO features in the core of PHP 5, and so will not run with earlier versions of PHP.


try {
    $connection = new PDO("msql:host='localhost';dbname='member_db', user, password);
    $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql_query = "select id, user_name";
    $row = $connection->query($sql_query);

    foreach ($row as list($id, $user_name))
    {
        echo $id."-".$user_name."<br>";
    }
}
catch(Exception $ex) {

    echo $ex->getMessage();
}
finally {

    $connection = null;
}



반응형

'IT > PHP' 카테고리의 다른 글

CONVERT_TZ : mysql 타임존 변경  (0) 2022.06.16
json_decode 함수 null 반환  (0) 2017.07.25
Mysql 의 Password() 함수로 만든 hash 를 bcrpyt 로 변경해주는 Wordpress plugin  (0) 2017.05.30
PHP MySqli 사용 예제  (0) 2016.10.19
PHP Trait  (0) 2016.10.07
PHP list 문  (0) 2016.10.03
Language construct  (0) 2016.09.25
Maria DB Query 사용법 및 기타 주의 사항  (0) 2016.09.12
PHP namespace  (0) 2016.08.21
PHP Array  (0) 2016.08.03

댓글