Wednesday, December 23, 2015

The Best Way to Connect to the Database

I've been thinking about writing an article on the best way to connect a web server to the database.

I can't write this article because, for some unknown reason, I cannot get PDO to work on PHP7. I've completely removed and reinstalled PHP a half dozen times and it simply doesn't work.

I've spent more time battling PDO than I've spent battling any piece of software in my life.

I've had inconsistent results with PDO on every server that I've encountered. There is something seriously wrong with PDO.

Since I can't get PDO to work with SQLite3. I decided to install PostgreSQL.

I didn't want to install the full application on my account. So, I Googled "postgresql hosting" and found someone reselling Amazon Web Services.

ADVERTISEMENT: You can get access to free (but limited) database hosting with Amazon Web Services. NOTE: This link sets an affiliate cookie. I might get a commission on sales. Of course, you are buying something for $0; So, my commission won't actually be anything, but at least it is a sale. It is better to get a commission on nothing than to not get a commission on anything ... or something like that.

If you don't want to go through my affiliate link, you can just type in your browser.

You can sign up for a PostgreSQL or other database. It will create a and user for you. You can then install the PostgreSQL client on your web server (or home computer) and start accessing the database.

On Ubuntu, you install the postgresql client with the command "sudo apt-get install postgresql-client".

After installing the client, you can access your Amazon hosted database from the command line with psql.

It was like  magic. I was able to create and update tables on the Amazon server.

The next step is to connect PosgreSQL with php. There are different modules for different databases. I installed the module for PHP7.0 with the command "sudo apt-get install  php7.0-pgsql"

And ... it doesn't work. I can query the database, but I am unable to modify the database with the PDOStatement->execute() command.

Anyway, as soon as I figure out how to get PDO to work on PHP 7.0. I am going to write that article on the short comings of PDO.

Unfortunately, I can't write that article until I get the damn thing to work.

Although I am frustrated to no end with PDO, I love having a free database on Here is the affiliate link for those of you who skipped the advertisemnet: Amazon Web Services

No comments: