Script Perfect

         Random snips of code and bugs

PHP Database Class, The Right Way

Posted by Tim On September - 8 - 2009

How many times do your fingers type out the commands to run a query or fetch a row? If you are performing database tasks on the majority of your pages and you have not simplified the process then you need to keep reading. Developing a database class is not very difficult, in fact there are plenty of them out there which can set you on your way. Once you start using them you will most likely never go back.

A database class should be thorough, simple, and save you time. A single command to connect or disconnect as well as most of your common functions should be included. Do not re-invent the wheel if you have a large scale project, there are plenty of pre-build APIs which will handle much more than the examples given here. Below is a simple class which can get you up and running as well as examples of how to use it, let’s take a look:

Read the rest of this entry »

Multiple Sites or Domains, One Server, One DB

Posted by Tim On September - 2 - 2009

While messing around with some of my other sites I ran into a major problem. I had developed a great deal of conent for the main site and thought it would be great to make a seperate site for mobile users. The new site would of course be much smaller and compact but still allow the majority of data from the main site to be viewed.

When I started developing the mobile siteĀ  hit a brick wall, I could not connect to the database on my main site even though both sites were on the same server. I tried connecting to localhost as well as the IP address, specifying the db name or calling it from the query. Needless to say it tooks hours to figure out what was going on so here is my solution.

Read the rest of this entry »

About Me

I am an independent web developer and webmaster of many sites. The main goal of Script Perfect is to provide answers to some of the hard to find questions when it comes to website design and coding.

Twitter