PDO: Skillnad mellan sidversioner

Från Wiki.linux.se
Hoppa till navigering Hoppa till sök
(Skapade sidan med '== PDO-klassen == '''(PHP 5 >= 5.1.0, PHP 7, PHP 8, PECL pdo >= 0.1.0)''' === Introduktion === Representerar en anslutning mellan PHP och en databasserver. === Klassöversikt === <pre> class PDO { →‎Konstanter: public const int PARAM_NULL; public const int PARAM_BOOL = 5; public const int PARAM_INT = 1; public const int PARAM_STR = 2; public const int PARAM_LOB = 3; public const int PARAM_STMT = 4; public const int PARAM_INPUT_OUTPUT; public const int PARAM_STR_NATL...')
 
Ingen redigeringssammanfattning
Rad 1: Rad 1:
== PDO-klassen ==
= PHP Data Objects (PDO) =
'''(PHP 5 >= 5.1.0, PHP 7, PHP 8, PECL pdo >= 0.1.0)'''
PDO är en lättviktig och konsekvent gränssnitt för att komma åt databaser i PHP. Det erbjuder en databasabstraktionslager som gör att samma funktioner kan användas för olika databaser.


=== Introduktion ===
== Innehåll ==
Representerar en anslutning mellan PHP och en databasserver.
* [[#Introduction|Introduction]]
* [[#Installing_Configuring|Installing/Configuring]]
** [[#Installation|Installation]]
** [[#Runtime_Configuration|Runtime Configuration]]
* [[#Predefined_Constants|Predefined Constants]]
* [[#Connections_and_Connection_management|Connections and Connection management]]
* [[#Transactions_and_auto_commit|Transactions and auto-commit]]
* [[#Prepared_statements_and_stored_procedures|Prepared statements and stored procedures]]
* [[#Errors_and_error_handling|Errors and error handling]]
* [[#Large_Objects_LOBs|Large Objects (LOBs)]]
* [[#PDO|PDO — The PDO class]]
** [[PDO::beginTransaction()]] — Initiates a transaction
** [[PDO::commit()]] — Commits a transaction
** [[PDO::connect()]] — Connect to a database and return a PDO subclass for drivers that support it
** [[PDO::__construct()]] — Creates a PDO instance representing a connection to a database
** [[PDO::errorCode()]] — Fetch the SQLSTATE associated with the last operation on the database handle
** [[PDO::errorInfo()]] — Fetch extended error information associated with the last operation on the database handle
** [[PDO::exec()]] — Execute an SQL statement and return the number of affected rows
** [[PDO::getAttribute()]] — Retrieve a database connection attribute
** [[PDO::getAvailableDrivers()]] — Return an array of available PDO drivers
** [[PDO::inTransaction()]] — Checks if inside a transaction
** [[PDO::lastInsertId()]] — Returns the ID of the last inserted row or sequence value
** [[PDO::prepare()]] — Prepares a statement for execution and returns a statement object
** [[PDO::query()]] — Prepares and executes an SQL statement without placeholders
** [[PDO::quote()]] — Quotes a string for use in a query
** [[PDO::rollBack()]] — Rolls back a transaction
** [[PDO::setAttribute()]] — Set an attribute
* [[#PDOStatement|PDOStatement — The PDOStatement class]]
** [[PDOStatement::bindColumn()]] — Bind a column to a PHP variable
** [[PDOStatement::bindParam()]] — Binds a parameter to the specified variable name
** [[PDOStatement::bindValue()]] — Binds a value to a parameter
** [[PDOStatement::closeCursor()]] — Closes the cursor, enabling the statement to be executed again
** [[PDOStatement::columnCount()]] — Returns the number of columns in the result set
** [[PDOStatement::debugDumpParams()]] — Dump an SQL prepared command
** [[PDOStatement::errorCode()]] — Fetch the SQLSTATE associated with the last operation on the statement handle
** [[PDOStatement::errorInfo()]] — Fetch extended error information associated with the last operation on the statement handle
** [[PDOStatement::execute()]] — Executes a prepared statement
** [[PDOStatement::fetch()]] — Fetches the next row from a result set
** [[PDOStatement::fetchAll()]] — Fetches the remaining rows from a result set
** [[PDOStatement::fetchColumn()]] — Returns a single column from the next row of a result set
** [[PDOStatement::fetchObject()]] — Fetches the next row and returns it as an object
** [[PDOStatement::getAttribute()]] — Retrieve a statement attribute
** [[PDOStatement::getColumnMeta()]] — Returns metadata for a column in a result set
** [[PDOStatement::getIterator()]] — Gets result set iterator
** [[PDOStatement::nextRowset()]] — Advances to the next rowset in a multi-rowset statement handle
** [[PDOStatement::rowCount()]] — Returns the number of rows affected by the last SQL statement
** [[PDOStatement::setAttribute()]] — Set a statement attribute
** [[PDOStatement::setFetchMode()]] — Set the default fetch mode for this statement
* [[#PDORow|PDORow — The PDORow class]]
* [[#PDOException|PDOException — The PDOException class]]
* [[#PDO_Drivers|PDO Drivers]]
** [[#CUBRID_PDO|CUBRID (PDO) — CUBRID Functions (PDO_CUBRID)]]
** [[#MS_SQL_Server_PDO|MS SQL Server (PDO) — Microsoft SQL Server and Sybase Functions (PDO_DBLIB)]]
** [[#Pdo_Dblib|Pdo\Dblib — The Pdo\Dblib class]]
** [[#Firebird_PDO|Firebird (PDO) — Firebird Functions (PDO_FIREBIRD)]]
** [[#Pdo_Firebird|Pdo\Firebird — The Pdo\Firebird class]]
** [[#IBM_PDO|IBM (PDO) — IBM Functions (PDO_IBM)]]
** [[#Informix_PDO|Informix (PDO) — Informix Functions (PDO_INFORMIX)]]
** [[#MySQL_PDO|MySQL (PDO) — MySQL Functions (PDO_MYSQL)]]
** [[#Pdo_Mysql|Pdo\Mysql — The Pdo\Mysql class]]
** [[#MS_SQL_Server_PDO_SQLSRV|MS SQL Server (PDO) — Microsoft SQL Server Functions (PDO_SQLSRV)]]
** [[#Oracle_PDO|Oracle (PDO) — Oracle Functions (PDO_OCI)]]
** [[#ODBC_DB2_PDO|ODBC and DB2 (PDO) — ODBC and DB2 Functions (PDO_ODBC)]]
** [[#Pdo_Odbc|Pdo\Odbc — The Pdo\Odbc class]]
** [[#PostgreSQL_PDO|PostgreSQL (PDO) — PostgreSQL Functions (PDO_PGSQL)]]
** [[#Pdo_Pgsql|Pdo\Pgsql — The Pdo\Pgsql class]]
** [[#SQLite_PDO|SQLite (PDO) — SQLite Functions (PDO_SQLITE)]]
** [[#Pdo_Sqlite|Pdo\Sqlite — The Pdo\Sqlite class]]


=== Klassöversikt ===
<pre>
class PDO {
/* Konstanter */
public const int PARAM_NULL;
public const int PARAM_BOOL = 5;
public const int PARAM_INT = 1;
public const int PARAM_STR = 2;
public const int PARAM_LOB = 3;
public const int PARAM_STMT = 4;
public const int PARAM_INPUT_OUTPUT;
public const int PARAM_STR_NATL;
public const int PARAM_STR_CHAR;
public const int PARAM_EVT_ALLOC;
public const int PARAM_EVT_FREE;
public const int PARAM_EVT_EXEC_PRE;
public const int PARAM_EVT_EXEC_POST;
public const int PARAM_EVT_FETCH_PRE;
public const int PARAM_EVT_FETCH_POST;
public const int PARAM_EVT_NORMALIZE;
public const int FETCH_DEFAULT;
public const int FETCH_LAZY;
public const int FETCH_ASSOC;
public const int FETCH_NUM;
public const int FETCH_BOTH;
public const int FETCH_OBJ;
public const int FETCH_BOUND;
public const int FETCH_COLUMN;
public const int FETCH_CLASS;
public const int FETCH_INTO;
public const int FETCH_FUNC;
public const int FETCH_GROUP;
public const int FETCH_UNIQUE;
public const int FETCH_KEY_PAIR;
public const int FETCH_CLASSTYPE;
public const int FETCH_SERIALIZE;
public const int FETCH_PROPS_LATE;
public const int FETCH_NAMED;
public const int ATTR_AUTOCOMMIT;
public const int ATTR_PREFETCH;
public const int ATTR_TIMEOUT;
public const int ATTR_ERRMODE;
public const int ATTR_SERVER_VERSION;
public const int ATTR_CLIENT_VERSION;
public const int ATTR_SERVER_INFO;
public const int ATTR_CONNECTION_STATUS;
public const int ATTR_CASE;
public const int ATTR_CURSOR_NAME;
public const int ATTR_CURSOR;
public const int ATTR_ORACLE_NULLS;
public const int ATTR_PERSISTENT;
public const int ATTR_STATEMENT_CLASS;
public const int ATTR_FETCH_TABLE_NAMES;
public const int ATTR_FETCH_CATALOG_NAMES;
public const int ATTR_DRIVER_NAME;
public const int ATTR_STRINGIFY_FETCHES;
public const int ATTR_MAX_COLUMN_LEN;
public const int ATTR_EMULATE_PREPARES;
public const int ATTR_DEFAULT_FETCH_MODE;
public const int ATTR_DEFAULT_STR_PARAM;
public const int ERRMODE_SILENT;
public const int ERRMODE_WARNING;
public const int ERRMODE_EXCEPTION;
public const int CASE_NATURAL;
public const int CASE_LOWER;
public const int CASE_UPPER;
public const int NULL_NATURAL;
public const int NULL_EMPTY_STRING;
public const int NULL_TO_STRING;
public const string ERR_NONE;
public const int FETCH_ORI_NEXT;
public const int FETCH_ORI_PRIOR;
public const int FETCH_ORI_FIRST;
public const int FETCH_ORI_LAST;
public const int FETCH_ORI_ABS;
public const int FETCH_ORI_REL;
public const int CURSOR_FWDONLY;
public const int CURSOR_SCROLL;
/* Metoder */
public __construct(
    string $dsn,
    ?string $username = null,
    #[\SensitiveParameter] ?string $password = null,
    ?array $options = null
)
public beginTransaction(): bool
public commit(): bool
public static connect(
    string $dsn,
    ?string $username = null,
    #[\SensitiveParameter] ?string $password = null,
    ?array $options = null
): static
public errorCode(): ?string
public errorInfo(): array
public exec(string $statement): int|false
public getAttribute(int $attribute): mixed
public static getAvailableDrivers(): array
public inTransaction(): bool
public lastInsertId(?string $name = null): string|false
public prepare(string $query, array $options = []): PDOStatement|false
public query(string $query, ?int $fetchMode = null): PDOStatement|false
public query(string $query, ?int $fetchMode = PDO::FETCH_COLUMN, int $colno): PDOStatement|false
public query(
    string $query,
    ?int $fetchMode = PDO::FETCH_CLASS,
    string $classname,
    array $constructorArgs
): PDOStatement|false
public query(string $query, ?int $fetchMode = PDO::FETCH_INTO, object $object): PDOStatement|false
public quote(string $string, int $type = PDO::PARAM_STR): string|false
public rollBack(): bool
public setAttribute(int $attribute, mixed $value): bool
}
</pre>
=== Ändringslogg ===
{| class="wikitable"
! Version
! Beskrivning
|-
| 8.4.0
| Klasskonstanterna är nu typade.
|}
=== Innehållsförteckning ===
* [[PDO::beginTransaction]] — Initierar en transaktion
* [[PDO::commit]] — Bekräftar en transaktion
* [[PDO::connect]] — Ansluter till en databas och returnerar en PDO-underklass för drivrutiner som stöder det
* [[PDO::__construct]] — Skapar en PDO-instans som representerar en databasanslutning
* [[PDO::errorCode]] — Hämtar SQLSTATE som är associerad med den senaste operationen på databasanslutningen
* [[PDO::errorInfo]] — Hämtar utökad felinformation för den senaste operationen
* [[PDO::exec]] — Utför ett SQL-uttryck och returnerar antalet påverkade rader
* [[PDO::getAttribute]] — Hämtar en databasanslutningsattribut
* [[PDO::getAvailableDrivers]] — Returnerar en array med tillgängliga PDO-drivrutiner
* [[PDO::inTransaction]] — Kontrollerar om det finns en aktiv transaktion
* [[PDO::lastInsertId]] — Returnerar ID:t för den senaste insatta raden eller sekvensvärdet
* [[PDO::prepare]] — Förbereder ett uttalande för exekvering och returnerar ett uttalande-objekt
* [[PDO::query]] — Förbereder och exekverar ett SQL-uttryck utan platshållare
* [[PDO::quote]] — Citerar en sträng för användning i en fråga
* [[PDO::rollBack]] — Rullar tillbaka en transaktion
* [[PDO::setAttribute]] — Ställer in ett attribut


= Sidslut =
= Sidslut =


Orginalhemsidan på Engelska :https://www.php.net/manual/en/class.pdo.php
Orginalhemsidan på Engelska :https://www.php.net/manual/en/book.pdo.php
<BR>[[PHP]]
<BR>[[PHP]]
[[Funktioner]]
[[Funktioner]]

Versionen från 22 december 2024 kl. 07.46

PHP Data Objects (PDO)

PDO är en lättviktig och konsekvent gränssnitt för att komma åt databaser i PHP. Det erbjuder en databasabstraktionslager som gör att samma funktioner kan användas för olika databaser.

Innehåll


Sidslut

Orginalhemsidan på Engelska :https://www.php.net/manual/en/book.pdo.php
PHP Funktioner Funktionsreferens Databas-tillägg


Det här är en maskinöversättning av PHP-manualen till svenska. Om du hittar fel är vi tacksamma om du rapporterar dem via formuläret som finns på https://www.linux.se/kontaka-linux-se/

Tack till Huddinge Datorhjälp som har sponsrat Linux.se med webbhotell.