Handling errors when connecting to a database using PHP PDO

PHP’s PDO database abstraction class offers a better way to connect to databases than the mysql_* etc style functions, or using a 3rd party database library. This post looks at handle errors when connecting and a follow up post later this week will look at how to check for errors when running individual queries after a connection has been successfully established.

Categories PHP

Disable auto renew at GoDaddy

I use GoDaddy to register my domain names and secure certificates. When a new product is bought from GoDaddy it will be default set to auto-renew. I prefer to manually renew everything and this post shows how to disable auto renewal at GoDaddy. Following these instructions you can also change a product from not auto-renewing to auto-renew.

Install APC for PHP on Debian 5 Lenny

I have recently moved from hosting on a CentOS box to Debian and needed to install PHP’s APC opcode cache on it. I’ve posted about how to do this before on a CentOS box which is a very manual process and now add this post to install APC on Debian which is much easier.

As the root user or using sudo run the following command:

aptitude install php-apc

Everything else is done for you and all that is needed now is to gracefully reload Apache, again running as the root user or using sudo:

apache2ctl graceful

The configuration file is at /etc/php5/conf.d/apc.ini should you wish to change any of the settings such as the APC memory size etc.

If you want to have a page showing the current APC statistics, run the following command:

gzip -dc /usr/share/doc/php-apc/apc.php.gz > /path/to/apc.php

Make sure /path/to/apc.php is a location available in a web browser (and ideally password and/or IP address restricted) and then you can view detailed statistical information. I have some screenshots available here from an older post.

Fetching data using PHP and PDO with bound placeholders

This post shows how to fetch data from a MySQL database using PHP’s PDO library with bound placeholders. This is a fairly basic tutorial and the functions used in it will be used in a post tomorrow titled "Load JSON data with jQuery, PHP and MySQL".