PHP » GoLang |
login |
register |
about
|
GoLang PDO::__construct
request it (506)
GoLang replacement for PHP's PDO::__construct
[edit | history]
PDO::__construct(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0) PDO::__construct — Creates a PDO instance representing a connection to a database Description
public PDO::__construct
( string
$dsn
[, string $username
[, string $passwd
[, array $options
]]] )Creates a PDO instance to represent a connection to the requested database. Parameters
Return ValuesReturns a PDO object on success. Errors/ExceptionsPDO::__construct() throws a PDOException if the attempt to connect to the requested database fails. Examples
Example #1 Create a PDO instance via driver invocation
<?php Example #2 Create a PDO instance via URI invocation The following example assumes that the file /usr/local/dbconnect exists with file permissions that enable PHP to read the file. The file contains the PDO DSN to connect to a DB2 database through the PDO_ODBC driver: odbc:DSN=SAMPLE;UID=john;PWD=mypass The PHP script can then create a database connection by simply passing the uri: parameter and pointing to the file URI:
<?php Example #3 Create a PDO instance using an alias The following example assumes that php.ini contains the following entry to enable a connection to a MySQL database using only the alias mydb: [PDO] pdo.dsn.mydb="mysql:dbname=testdb;host=localhost"
<?php Changelog
|
more
Recently updated
more
Most requested
more
Last requests
|