|
użytkowników online: 57
|
OPINIE UŻYTKOWNIKÓW
|
Mimo, że strony WWW tworzymy już 5 lat zawsze znajdziemy coś ciekawego. Świadczy o tym chociażby nasza aktówka, w której znajduje się kilkadziesiąt porad, z których często korzystamy. Otwarta forma poradnika, czyli możliwość podrzucania tematów oraz wspólny ich rozwój, to nieoceniona pomoc. Uważam, ze abonament roczny jest niewspółmiernie niski do jakości zaprezentowanych materiałów.
Marek Kończal
Internetix.pl
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
XCVIII. PDO Functions
| Ostrzeżenie | Ten moduł jest w stadium
EKSPERYMENTALNYM. Oznacza to, że zachowanie tych funkcji,
ich nazwy, w zasadzie wszystko udokumentowane tutaj może zostać zmienione w
przyszłych wersjach PHP bez wcześniejszego uprzedzenia. Używaj tego modułu na
własne ryzyko. |
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.
Windows
Follow the same steps to install and enable the PDO drivers of your
choice.
Windows users can download the extension DLL php_pdo.dll
as part of the PECL collection binaries from
/downloads.php or a more
recent version from a PHP 5 PECL
Snapshot.
To enable the PDO extension on Windows operating systems, you must
add the following line to php.ini:
Next, choose the other DB specific DLL files and either use
dl() to load them at runtime, or enable them in
php.ini below pdo_pdo.dll. For example:
extension=php_pdo.dll
extension=php_pdo_firebird.dll
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll |
These DLL's should exist in the systems
extension_dir.
Linux and UNIX
Due to a bug in the pear installer you should install
the PDO package manually using the following steps:
Follow the same steps to install and enable the PDO drivers of your
choice.
Download the PDO package to your local machine:
bash$ wget http://pecl.php.net/get/PDO |
Determine your PHP bin directory. If your
PHP 5 CLI binary lives at /usr/local/php5/bin/php
then the bin dir is /usr/local/php5/bin.
Set your path so that your PHP bin directory
is at the front:
export PATH="/usr/local/php5/bin:$PATH" |
Manually build and install the PDO extension:
bash$ tar xzf PDO-0.2.tgz
bash$ cd PDO-0.2
bash$ phpize
bash$ ./configure
bash$ make
bash$ sudo -s
bash# make install
bash# echo extension=pdo.so >> /usr/local/php5/lib/php.ini |
The following drivers currently implement the PDO interface:
Represents a connection between PHP and a database server.
beginTransaction
- begins a transaction
commit
- commits a transaction
exec
- issues an SQL statement and returns the number of affected rows
errorCode
- retrieves an error code, if any, from the database
errorInfo
- retrieves an array of error information, if any, from the
database
getAttribute
- retrieves a database connection attribute
lastInsertId
- retrieves the value of the last row that was inserted into a table
prepare
- prepares an SQL statement for execution
query
- issues an SQL statement and returns a result set
quote
- returns a quoted version of a string for use in SQL statements
rollBack
- roll back a transaction
setAttribute
- sets a database connection attribute
Represents a prepared statement and, after the statement is executed, an
associated result set.
bindColumn
- binds a PHP variable to an output column in a result set
bindParam
- binds a PHP variable to a parameter in the prepared statement
columnCount
- returns the number of columns in the result set
errorCode
- retrieves an error code, if any, from the statement
errorInfo
- retrieves an array of error information, if any, from the statement
execute
- executes a prepared statement
fetch
- fetches a row from a result set
fetchAll
- fetches an array containing all of the rows from a result set
fetchSingle
- returns the data from the first column in a result set
getAttribute
- retrieves a PDOStatement attribute
getColumnMeta
- retrieves metadata for a column in the result set
rowCount
- returns the number of rows that were affected by the execution of
an SQL statement
setAttribute
- sets a PDOStatement attribute
setFetchMode
- sets the fetch mode for a PDOStatement
Poniższe stałe są zdefiniowane w tym rozszerzeniu i stają się dostępne, gdy
rozszerzenie jest dokompilowane do PHP, lub załadowane dynamicznie przy starcie.
- PDO_PARAM_NULL
(integer)
Represents the SQL NULL data type.
- PDO_PARAM_INT
(integer)
Represents the SQL INTEGER data type.
- PDO_PARAM_STR
(integer)
Represents the SQL CHAR, VARCHAR, or other string data type.
- PDO_PARAM_LOB
(integer)
Represents the SQL large object data type.
- PDO_PARAM_STMT
(integer)
- PDO_PARAM_INPUT_OUTPUT
(integer)
Specifies that the parameter is an INOUT parameter for a stored
procedure. You must bitwise-OR this value with an explicit
PDO_PARAM_* data type.
- PDO_FETCH_LAZY
(integer)
Specifies that the fetch method shall return each row as an object with
variable names that correspond to the column names returned in the result
set. PDO_FETCH_LAZY creates the object variable names as they are accessed.
- PDO_FETCH_ASSOC
(integer)
Specifies that the fetch method shall return each row as an array indexed
by column name as returned in the corresponding result set.
- PDO_FETCH_NUM
(integer)
Specifies that the fetch method shall return each row as an array indexed
by column number as returned in the corresponding result set, starting at
column 0.
- PDO_FETCH_BOTH
(integer)
Specifies that the fetch method shall return each row as an array indexed
by both column name and number as returned in the corresponding result set,
starting at column 0.
- PDO_FETCH_OBJ
(integer)
Specifies that the fetch method shall return each row as an object with
property names that correspond to the column names returned in the result
set.
- PDO_FETCH_BOUND
(integer)
Specifies that the fetch method shall return TRUE and assign the values of
the columns in the result set to the PHP variables to which they were
bound with the PDOStatement::bindParam() or
PDOStatement::bindColumn() methods.
- PDO_FETCH_COLUMN
(integer)
Specifies that the fetch method shall return only a single requested
column from the next row in the result set.
- PDO_FETCH_CLASS
(integer)
Specifies that the fetch method shall return a new instance of the
requested class, mapping the columns to named properties in the class.
- PDO_FETCH_INTO
(integer)
Specifies that the fetch method shall update an existing instance of the
requested class, mapping the columns to named properties in the class.
- PDO_FETCH_FUNC
(integer)
- PDO_FETCH_GROUP
(integer)
- PDO_FETCH_UNIQUE
(integer)
- PDO_FETCH_CLASSTYPE
(integer)
- PDO_ATTR_AUTOCOMMIT
(integer)
- PDO_ATTR_PREFETCH
(integer)
- PDO_ATTR_TIMEOUT
(integer)
- PDO_ATTR_ERRMODE
(integer)
- PDO_ATTR_SERVER_VERSION
(integer)
- PDO_ATTR_CLIENT_VERSION
(integer)
- PDO_ATTR_SERVER_INFO
(integer)
- PDO_ATTR_CONNECTION_STATUS
(integer)
- PDO_ATTR_CASE
(integer)
Force column names to a specific case specified by the PDO_CASE_*
constants.
- PDO_ATTR_CURSOR_NAME
(integer)
- PDO_ATTR_CURSOR
(integer)
- PDO_ATTR_ORACLE_NULLS
(integer)
- PDO_ATTR_PERSISTENT
(integer)
- PDO_ERRMODE_SILENT
(integer)
- PDO_ERRMODE_WARNING
(integer)
- PDO_ERRMODE_EXCEPTION
(integer)
- PDO_CASE_NATURAL
(integer)
Leave column names as returned by the database driver.
- PDO_CASE_LOWER
(integer)
Force column names to lower case.
- PDO_CASE_UPPER
(integer)
Force column names to upper case.
- PDO_FETCH_ORI_NEXT
(integer)
Fetch the next row in the result set. Valid only for scrollable cursors.
- PDO_FETCH_ORI_PRIOR
(integer)
Fetch the previous row in the result set. Valid only for scrollable
cursors.
- PDO_FETCH_ORI_FIRST
(integer)
Fetch the first row in the result set. Valid only for scrollable cursors.
- PDO_FETCH_ORI_LAST
(integer)
Fetch the last row in the result set. Valid only for scrollable cursors.
- PDO_FETCH_ORI_ABS
(integer)
Fetch the requested row by row number from the result set. Valid only
for scrollable cursors.
- PDO_FETCH_ORI_REL
(integer)
Fetch the requested row by relative position from the current position
of the cursor in the result set. Valid only for scrollable cursors.
- PDO_CURSOR_FWDONLY
(integer)
Create a PDOStatement object with a forward-only cursor. This may improve
the performance of your application but restricts your PDOStatement object
to fetching one row at a time from the result set in a forward direction.
- PDO_CURSOR_SCROLL
(integer)
Create a PDOStatement object with a scrollable cursor. Pass the
PDO_FETCH_ORI_* constants to control the rows fetched from the result set.
- PDO_ERR_CANT_MAP
(integer)
- PDO_ERR_SYNTAX
(integer)
- PDO_ERR_CONSTRAINT
(integer)
- PDO_ERR_NOT_FOUND
(integer)
- PDO_ERR_ALREADY_EXISTS
(integer)
- PDO_ERR_NOT_IMPLEMENTED
(integer)
- PDO_ERR_MISMATCH
(integer)
- PDO_ERR_TRUNCATED
(integer)
- PDO_ERR_DISCONNECTED
(integer)
- PDO_ERR_NO_PERM
(integer)
- PDO_ERR_NONE
(string)
Corresponds to SQLSTATE '00000', meaning that the SQL statement was
successfully issued with no errors or warnings.
User Contributed Notestomasz dot wasiluk at gmail dot com
01-Jan-2006 01:09
Watch out for putting spaces in the DSN
mysql:host=localhost;dbname=test works
mysql: host = localhost; dbname=test works
mysql: host = localhost; dbname = test doesn't work...
Matthias Leuffen
04-Dec-2005 10:36
Hi there,
because of ZDE 5.0 and other PHP-IDEs do not seem to support PDO from PHP5.1 in code-completion-database yet, I wrote a code-completion alias for the PDO class.
NOTE: This Class has no functionality and should be only included to your IDE-Project but NOT(!) to your application.
<?php
class PDO {
const ERR_ALREADY_EXISTS = 0;
const ERR_CANT_MAP = 0;
const ERR_NOT_FOUND = 0;
const ERR_SYNTAX = 0;
const ERR_CONSTRAINT = 0;
const ERR_MISMATCH = 0;
const ERR_DISCONNECTED = 0;
const ERR_NONE = 0;
const ATTR_ERRMODE = 0;
const ATTR_TIMEOUT = 0;
const ATTR_AUTOCOMMIT = 0;
const ATTR_PERSISTENT = 0;
const ERRMODE_EXCEPTION = 0;
const ERRMODE_WARNING = 0;
const FETCH_ASSOC = 0;
const FETCH_NUM = 0;
const FETCH_OBJ = 0;
public function __construct($uri, $user, $pass, $optsArr) {
}
public function prepare ($prepareString) {
}
public function query ($queryString) {
}
public function quote ($input) {
}
public function exec ($statement) {
}
public function lastInsertId() {
}
public function beginTransaction () {
}
public function commit () {
}
public function rollBack () {
}
public function errorCode () {
}
public function errorInfo () {
}
}
class PDOStatement {
public function bindValue ($no, $value) {
}
public function fetch () {
}
public function nextRowset () {
}
public function execute() {
}
public function errorCode () {
}
public function errorInfo () {
}
public function rowCount () {
}
public function setFetchMode ($mode) {
}
public function columnCount () {
}
}
ng4rrjanbiah at rediffmail dot com
16-Mar-2005 07:53
Some useful links on PDO:
1. PDO Wiki ( http://wiki.cc/php/PDO )
2. Introducing PHP Data Objects ( http://netevil.org/downloads/Introducing-PDO.ppt ), [226 KB], Wez Furlong, 2004-09-24
3. The PHP 5 Data Object (PDO) Abstraction Layer and Oracle ( http://www.oracle.com/technology/pub/articles/php_experts/otn_pdo_oracle5.html ), [60.85 KB], Wez Furlong, 2004-07-28
4. PDO - Why it should not be part of core PHP! ( http://www.akbkhome.com/blog.php/View/55/ ), Critical review, [38.63 KB], Alan Knowles, 2004-10-22
HTH,
R. Rajesh Jeba Anbiah
|