Accessing a SQL database
My Github repository at http://github.com/adamdruppe/arsd contains a database.d
interface file and implementation files for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server via ODBC. Here, we'll use them to perform some SQL queries.
Getting ready
Download database.d
and a driver file (postgres.d
for PostgreSQL, mysql.d
for MySQL, sqlite.d
for SQLite, or mssql.d
for SQL Server) from my Github.
The drivers also require C libraries. The mysql.d
file needs libmysqlclient
, which comes with the MySQL server. The postgres.d
file needs libpq
, which comes with the PostgreSQL server. The sqlite.d
file needs SQLite installed on the system.
Let's also create a test database to use from the program. In our example, we'll use MySQL, so create a MySQL database, user, and data table. The following are the commands you can run in the MySQL console:
create database demonstration; use demonstration grant all privileges on demonstration.* to 'demo_user'@'localhost' identified by 'test...