Jaxer.DB.MySQL.Connection : Object
Return to: Jaxer Framework index

Creates a new connection to the given databaseName (file).

Platform Support

Jaxer Server Framework Jaxer Client Framework
1.0 no

Constructors

Constructor Action Jaxer Server Framework Jaxer Client Framework
Jaxer.DB.MySQL.Connection Constructor(Object connectionParams) : Jaxer.DB.MySQL.Connection
Creates a new connection to the given databaseName. The resulting connection object is the only way to interact with the database.
Show Details 1.0 no

Jaxer.DB.MySQL.Connection(Object connectionParams) : Jaxer.DB.MySQL.Connection

Creates a new connection to the given databaseName. The resulting connection object is the only way to interact with the database.

Parameters
Object connectionParams A hashmap of required parameters to connect to the database. Required properties are HOST (hostname of the server), USER (username for authentication), PASS (password for authentication), NAME (database name), PORT (connection port, default value is "3306"), and CLOSE_AFTER_EXECUTE (whether to close the connection after each call to execute, default is open).

Returns
Jaxer.DB.MySQL.Connection Returns an instance of Connection.

Properties

Property Action Jaxer Server Framework Jaxer Client Framework
implementation : String
Returns the string identifying the database implementation of this connection. You can compare this e.g. to Jaxer.DB.SQLite.IMPLEMENTATION or Jaxer.DB.MySQL.IMPLEMENTATION
No Details 1.0 no
isOpen : Boolean
Is the connection currently open? Recall that even if the answer is no the connection would automatically be opened when needed.
No Details 1.0 no
lastInsertId : Number
Returns the unique ID used for an AUTO_INCREMENT column in the most recent successful INSERT command on the current connection. If no successful INSERTs have ever occurred on this connection, 0 is returned. Note that unsuccessful INSERTs do not change this value. This is a synonym for lastInsertRowId. See http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html for more details.
No Details 1.0 no
lastInsertRowId : Number
Returns the unique ID used for an AUTO_INCREMENT column in the most recent successful INSERT command on the current connection. If no successful INSERTs have ever occurred on this connection, 0 is returned. Note that unsuccessful INSERTs do not change this value. This is a synonym for lastInsertId. See http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html for more details.
No Details 1.0 no
version : String
Returns the string identifying the version of the database to which you are connected.
No Details 1.0 no

Functions

Method Action Jaxer Server Framework Jaxer Client Framework
close() : void
Closes the connection if it's open. This is optional, and only does something if the connection is open.
No Details 1.0 no
execute(String sql, Object params) : Array<Object>|Jaxer.DB.ResultSet|Number
Executes the given sql using the connection. If the SQL includes ?'s (question marks) as parameter placeholders, the values of those parameters should be passed in as extra arguments to this function, either as individual arguments or as a single array.
Show Details 1.0 no

Parameters
String sql The sql statement to be executed as a prepared statement
Object params The sequential parameters passed to the prepared statement for execution. If this is an array, it is used as the list of parameters. If this is one or more parameters, that is used as the list.

Returns
Array<Object> The results of the query. For a SELECT-type query, a Jaxer.DB.ResultSet is returned, with 0 or more rows. For an INSERT/UPDATE/DELETE-type query, the number of rows affected is returned. If multiple queries were issued (or a stored procedure was executed) the result will be a corresponding array of Jaxer.DB.ResultSet or Number objects.
Jaxer.DB.ResultSet The results of the query. For a SELECT-type query, a Jaxer.DB.ResultSet is returned, with 0 or more rows. For an INSERT/UPDATE/DELETE-type query, the number of rows affected is returned. If multiple queries were issued (or a stored procedure was executed) the result will be a corresponding array of Jaxer.DB.ResultSet or Number objects.
Number The results of the query. For a SELECT-type query, a Jaxer.DB.ResultSet is returned, with 0 or more rows. For an INSERT/UPDATE/DELETE-type query, the number of rows affected is returned. If multiple queries were issued (or a stored procedure was executed) the result will be a corresponding array of Jaxer.DB.ResultSet or Number objects.

Examples
 rs = conn.execute("SELECT * FROM myTable"); rs = conn.execute("SELECT * FROM myTable WHERE id=? AND zip=?", myId, myZip);
                        rs = conn.execute("SELECT * FROM myTable WHERE id=? AND zip=?", [ myId, myZip ] ); 
getLastInsertId() : Number
Returns the unique ID used for an AUTO_INCREMENT column in the most recent successful INSERT command on the current connection. If no successful INSERTs have ever occurred on this connection, 0 is returned. Note that unsuccessful INSERTs do not change this value. This is the same as asking for the lastInsertId or lastInsertRowId properties. See http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html for more details.
Show Details 1.0 no

Returns
Number The id, or 0

mapExecute(String sql, Array arrayOfParameters, [Object options]) : Array<Object>
Prepares the given SQL query string on the current default database (as defined in configApps.js) and then iteratively executes it over the given array of parameters.
Show Details 1.0 no

Parameters
String sql The SQL to execute, using ?'s (question marks) as parameter placeholders
Array arrayOfParameters An array of parameters to use for each execution. Each element of the array may itself be a single value or an array of values (corresponding to the ?'s in the SQL)
Object options (optional)An optional hashmap of options. Currently one option is supported: flatten. If its value is true, the returned result will be a single ResultSet with its rows being the concatenated rows of each query.

Returns
Array<Object> A corresponding array of Jaxer.DB.ResultSets or Numbers for each query, or a combined Jaxer.DB.ResultSet or Number if the 'flatten' option is true. For SELECT-type queries one or more Jaxer.DB.ResultSets are returned; for INSERT/UPDATE/DELETE-type queries the number of affected rows is returned.

Examples
 [ rsA, rsB ] = conn.mapExecute("SELECT * FROM myTable WHERE id=?", [ idA, idB ] ); [ rsA, rsB ] = conn.mapExecute("SELECT
                        * FROM myTable WHERE id=? AND zip=?", [ [ idA, zipA ] , [ idB, zipB ] ] ); 
See Also

Jaxer.DB.ResultSet

open() : void
Opens the connection so queries can be executed. This is optional, since if the connection is not open when it's asked to execute some SQL, it will open the connection automatically. Also closing the connection is optional.
No Details 1.0 no
test(Boolean keepOpen) : Object
Tests the connection by trying to connect and catching and returning any error encountered. If the connection is successful, returns a null.
Show Details 1.0 no

Parameters
Boolean keepOpen If true, the connection will be kept open (if the test was successful). If false, the connection will be left in the same state as before the test: if it was open before it will be kept open, otherwise it will be closed.

Returns
Object If successful, returns null; if unsuccessful, returns the error. Usually you can use the error's sqlErrorCode and sqlErrorDescription to see what the error was (or just its toString() method).

aptana_docs