This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Ape.MySQL
Pablo Tejada edited this page Aug 25, 2013
·
5 revisions
Ape.MySQL is a class constructor. You can use it to connect and use a MySQL database.
Ape.MySQL( host, username, password, database)
- host: Mysql host, can be an ip:port or an unix socket.
- username: MySQL username.
- password: MySQL password.
- database: The database to select.
var sql = new Ape.MySQL("ip:port", "user", "password", "database");
sql.onConnect = function() {
Ape.log('Connected to mysql server');
}
sql.query("SELECT * FROM table", function(res, errorNo) {
if (errorNo) Ape.log('Request error : ' + errorNo + ' : '+ this.errorString());
else {
Ape.log('Fetching ' + res.length);
res.each(function(data) {
Ape.log(data.content);//data.<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');
});