O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—Connecting to the database

In our main function, let's initiate the connection to our database and the SPOD system:

import Post;
class Main
{
public static function main()
{
//Parameters to connect to the MySQL database
var cnx = neko.db.Mysql.connect({
host : "localhost",
port : 3306,
database : "myBlog",
user : "root",
pass : "",
});
//Initialize the SPOD system
neko.db.Manager.cnx = cnx;
neko.db.Manager.initialize();
//We've done our processing, let's clean things and disconnect
neko.db.Manager.cleanup();
cnx.close();
}
}

When doing this, we can successfully connect to the database although it won't do anything at the moment.

Now, let's just retrieve our posts from the database by simply adding this:

var posts = Post.manager.all(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required