db_open_database

resource db_open_database (string database [, string path [, string username [, string password]]])

Opens an existing database or creates a new one. If the database is not found, it will be created and opened.

Arguments

database is the name of the database to be opened.
path is an optional URL or path to the database.
username and password are optional parameters to grant access to the database.

Result

The result will be a database resource if successful or NULL otherwise.

Example

// 1. Open SQWLite database

include "db_common.inc.php";
define("WB_DATABASE", "SQLite");
define("PATH_DATA", "C:\winbinder\myApp\"); $database = "sample";

$dbhnd = db_open_database($database, PATH_DATA);
// opens the database c:\winbinder\myApp\SQLite_sample.db

// 2. Open MySQL database

include "db_common.inc.php";
define("APPPREFIX", "myDB_");
define("WB_DATABASE", "mySQL");
$database = "test";

db_open_database($database, $server = "192.168.168.133", $username = "root", $password = "");
// opens the database test on server 192.168.168.133 with user root and no password
// all tables will have a prefix myDB_ not seen by the application


See also

Database functions
Database support