D and MySQL

Adam Ruppe destructionator at gmail.com
Tue Jul 19 11:49:11 PDT 2011


I wrapped the libmysql C library in D and use it in a lot
of my apps.

https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff

Grab database.d and mysql.d from there.

To use it:

===
import arsd.mysql;

void main() {
   auto mysql = new MySql("localhost", "username", "password", "database name");

   // ? based placeholders do conversion and escaping for you
   foreach(line; mysql.query("select id, name from users where id > ?", 5)) {

           // access to columns by name
          writefln("%s: %s", line["id"], line["name"]);
          // alternatively, you can write:
          writefln("%s: %s", line[0], line[1]);

   }
}
=======


There's a lot of other stuff in there too, which I'll
write up in the next week or so... but this is the basics of it.


More information about the Digitalmars-d-learn mailing list