Class Database
Returns a connection to a MySQL server or a specific database. For connection the MySQL++ library is used. MySQL++ throws exceptions in case of errors, e.g. connection timeout.
Note that although the object is created with 'new' and there
is a 'delete' is JavaScript, it will not call any kind of
destructor. To close a Subscription you have to explicitly call
the close() member function. 'delete' in JavaScript is only
to remove a property from an Object.
Defined in: Database.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Database(database)
|
Field Attributes | Field Name and Description |
---|---|
<constant> |
Database which is connected
|
<constant> |
Port connected (if no port was given 'undefined')
|
<constant> |
Server which is connected
|
<constant> |
User connected to the database
|
Method Attributes | Method Name and Description |
---|---|
close()
Close the connection to the database.
|
|
query(arguments)
Returns the result of an sql query sent to the database.
|
Class Detail
Database(database)
var db = new Database("thomas@sql.at-home.com/database");
- Parameters:
- {String} database
- The databse argument is of this form (optional parts ar given in brackets):
user:password@server.domain.com[:port]/database
- Throws:
- If number or type of arguments is wrong
- If no connection could be opened, an exception with the reason is thrown.
Field Detail
<constant>
database
Database which is connected
<constant>
port
Port connected (if no port was given 'undefined')
<constant>
server
Server which is connected
<constant>
user
User connected to the database
Method Detail
{Boolean}
close()
Close the connection to the database.
The connection is automaically closed at cript termination.
- Returns:
- {Boolean} If the connection was successfully closed, i.e. it was still open, true is returned, false otherwise.
query(arguments)
Returns the result of an sql query sent to the database.
var table = db.query("SELECT * FROM table WHERE value BETWEEN", 5, "AND 20"); for (var row=0; row<table.length; row++) for (var col in table.cols) console.out("table["+row+"]['"+col+"']="+table[row][col]);
- Parameters:
- arguments
- The arguments specify the query to be sent
- Throws:
- If no connection could be opened, an exception with the reason is thrown.
- Returns:
- An array is returned. Each entry in the array corresponds to one row of the table and is expressed an an associative array (object). The names of the entries (columns) in each row are stored in a property cols which is an array itself. For convenience, table and query are stored in identically names properties.