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();
We now have the following:
import Post; class Main { public static function main() { ...