Jump to: navigation, search

PHP ADODB Connect

From w3cyberlearnings

Contents

PHP ADODB Connect

Connect to the database driver.

Syntax ADODB Connect to MySQL

include 'adodb5/adodb.inc.php';

$host = 'localhost';
$user = 'user2000';
$pass = 'password2000';
$dbname = 'w3cyberlearning';

$conn1 = &ADONewConnection('mysql');
$conn1->PConnect($host, $user, $pass, $dbname);

Example 1: mySQL

<?php
include 'adodb5/adodb.inc.php';

$host = 'localhost';
$user = 'user2000';
$pass = 'password2000';
$dbname = 'w3cyberlearning';

$conn1 = &ADONewConnection('mysql');
$conn1->PConnect($host, $user, $pass, $dbname);

?>

Example 2: Postgresql

<?php
include 'adodb5/adodb.inc.php';

$host = 'localhost';
$user = 'user2000';
$pass = 'password2000';
$dbname = 'w3cyberlearning';

$conn1 = &ADONewConnection('postgres');
$conn1->PConnect($host, $user, $pass, $dbname);

?>

Example 3:DB2

<?php
include 'adodb5/adodb.inc.php';

$host = 'localhost';
$user = 'user2000';
$pass = 'password2000';
$dbname = 'w3cyberlearning';

$conn1 = &ADONewConnection('db2');
$dsn ="driver={IBM db2 odbc DRIVER};Database={$dbname};hostname={$host};port=50000;protocol=TCPIP;".
                                   "uid={$user}; pwd={$pass}";
$conn1->PConnect($dns);

?>

Example 4: SQLite

$conn = &ADONewConnection('sqlite');
         $conn->PConnect('c:\path\to\sqlite.db'); # sqlite will create if does not exist

OR
// linux
$conn = &ADONewConnection('sqlite');
         $conn->PConnect('/path/to/sqlite.db'); # sqlite will create if does not exist

Related Links


Navigation
Web
SQL
MISC
References