Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

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)

Parameters

  • host: Mysql host, can be an ip:port or an unix socket.
  • username: MySQL username.
  • password: MySQL password.
  • database: The database to select.

Example

Database connection
var sql = new Ape.MySQL("ip:port", "user", "password", "database");

    sql.onConnect = function() {
        Ape.log('Connected to mysql server');
    }
Select request
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>
            });
        }
    });
Insert request
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');
    });
Clone this wiki locally