MySQL.query
(since 1.0)
Execute a mysql query
Description
string
MySQL.query
(
string query, function fn )
Used to execute a mysql query, the callback is called when the request ends, if it was a SELECT query, res contains an array of objects.
For now callback function is mandatory, if you don't want your request to have a callback function, use $empty as second argument
Parameters
query
The mysql query string
fn
- result - (array) An array of objects if the query was a "SELECT" query.
- errorNo - (number) If an error occurred the error code.
Examples
sql.query("SELECT * FROM table", function(res, errorNo) {
if (errorNo) Ape.log('Request error : ' + errorNo + ' : '+ this.errorString());
else {
Ape.log('Fetching ' + res.length);
for(var i = 0; i < res.length; i++) {
Ape.log(res[i].title);//res[i].<column name>
});
}
});
sql.query("INSERT INTO table VALUES('a','b','c')", function(res, errorNo) {
if (errorNo) Ape.log('Request error : ' + errorNo + ' : '+ this.errorString());
else Ape.log('Inserted');
});
User notes
# No comment
Post a note
CollaborAPE to our wiki !
Find the information you need on the APE Official Wiki : Install, Server, JSF, Help...
