Name

Connection — open a database connection

Synopsis

new Connection ( datasource,  
  username,  
  password);  
string   datasource ;
string   username ;
string   password ;

Description

Opens a connection to the data source identified by datasource. If the data source does not exist or if there is an error opening the connection then null is returned. Use error() to get the error message.

Optionally you can specify the parameters username and password. Note that you cannot specify one and not the other. If they are not specified and the data source requires user authentication then the connection attempt will fail.

Example 59. Connection Example

Connection conn = new Connection("MySQL Data Source");
if(conn == null)
{
    print("<p>Error connecting to data source: " + error() + "</p>");
}
else
{
    /*
     *
     * Do stuff ...
     *
     */
    conn.close();
}

See Also

Data sources and database access in RSP is explained in the section called “Accessing Databases”