Tools for developers

See more about:

Where are we?

You’ve seen that clients send SQL statements to DBMS. There are tools that write SQL statements for you, saving you some work. Let’s talk about phpMyAdmin, the most widely used tool for managing MySQL databases.

This lesson’s goals

You’ll learn:

  • To do database work, you need to send SQL statements to a DBMS. But some SQL statements are long and easy to mess up.
  • phpMyAdmin is a PHP Web application that writes SQL for you. phpMyAdmin is part of XAMPP.
  • You’ll see how to start MySQL and phpMyAdmin on your computer. You’ll see how to use phpMyAdmin on your hosting account.
  • You can create databases on your local computer, and use phpMyAdmin to export your work to your hosting account.

phpMyAdmin

Almost everything you do with MySQL is done by sending SQL commands to the server:

Everything is SQL

Figure 1. Everything is SQL

When you make Web applications, there’s some work you need to do to get things ready for your PHP pages. You create databases, make tables, add fields (columns), and other things.

This is done with SQL. But doing it all manually can be a pain. You have to type out long commands like this:

CREATE TABLE products (
   product_id int(11) NOT NULL AUTO_INCREMENT,
   'name' char(50) NOT NULL,
   description text NOT NULL,
   image_file_name char(50) NOT NULL,
   price decimal(10,2) NOT NULL,
   PRIMARY KEY (product_id)
);

And you have to get everything just right. You might make a mistake, like this:

CREATE TABLE products (
   product_id int(11) NOT NULL AUTO_INCREMENT,
   'name' char(50) NOT NULL,
   description text NOT NULL,
   image_file_name char(50) NOT NULL,
   price decimal(10,2) NOT NULL,
   PRIMARY KEY (prodct_id)
);

It wouldn’t work, but the problem is hard to spot. Grrrr!

There are tools that make it easier.

The one that most people use is phpMyAdmin. It’s actually just a bunch of PHP pages.

Most Web hosting companies install phpMyAdmin for you. It’s also part of the XAMPP package. If you installed XAMPP, you already have phpMyAdmin installed.

So you will have two copies of phpMyAdmin:

  • One on your local computer.
  • One on your hosting account.

You also have two different MySQL instances:

  • One running on your local machine.
  • One running on your hosting account.

Starting MySQL and phpMyAdmin on your local machine

Open the XAMPP control panel. Start both Apache and MySQL:

XAMPP control panel

Figure 2. XAMPP control panel

phpMyAdmin is a bunch of Web pages. It needs Apache (or another Web server) to run.

Start your browser, and go to http://localhost/. You’ll see this on the left:

XAMPP home page

Figure 3. XAMPP home page

Click the phpMyAdmin link to start it.

Starting phpMyAdmin on your Hostgator account

Log in to your Hostgator control panel. Scroll down to the Databases section:

Starting phpMyAdmin on Hostgator

Figure 4. Starting phpMyAdmin on Hostgator

If you aren’t using Hostgator, you’ll start phpMyAdmin in a different way. Check you hosting company’s help pages.

CC
CC

How do I start MySQL on my hosting account?

Kieran
Kieran

You don’t. MySQL is always running, just like Apache is always running.

Exercise: Starting phpMyAdmin

Start MySQL on your computer. Then open a browser, and run phpMyAmdin.

Run phpMyAdmin on your hosting account.

(Log in to enter your solution to this exercise.)

Different versions

The phpMyAdmin installation on your local computer might be a different version from the one on your hosting account. As I write this, I’m running version 2.10.3 on my local machine, and version 2.11.9.5 on my hosting account.

Even the versions of MySQL are different. I’m running MySQL version 5.0.45 on my local machine, and version 5.1.30 on my hosting account.

That’s OK. We’re only covering DB basics. At the level we’re working, having different versions won’t matter. The things we’re looking at have been more-or-less the same for twenty years.

And they’re still current. The core of DB tech has been unusually stable.

From local to remote

In earlier chapters, I recommended that you install XAMPP on your own computer, and write PHP programs there. When everything is working, then you upload the finished programs to your hosting account.

Adding databases complicates things a little, but not much. You can create databases on your local machine, and then move them to your hosting account when you’re ready.

phpMyAdmin can both import and export databases, tables, and other objects. So you can just copy most of your work from your local computer to your hosting account.

I’ll go over an example when we get to creating a table.

Other tools

There are many other tools that can help you work with databases. Earlier, I recommended Netbeans for writing Web pages. Netbeans has an integrated DB tool that works nicely with MySQL.

However, to keep things simple, we’ll only use phpMyAdmin. It’s already installed on both your development (local) and production (hosting account) servers. The same tool works no matter where you are.

Going deeper

You can read a review of Netbean’s database explorer.

Summary

  • To do database work, you need to send SQL statements to a DBMS. But some SQL statements are long and easy to mess up.
  • phpMyAdmin is a PHP Web application that writes SQL for you. phpMyAdmin is part of XAMPP.
  • We saw how to start MySQL and phpMyAdmin on your computer. We saw how to use phpMyAdmin on your hosting account.
  • You can create databases on your local computer, and use phpMyAdmin to export your work to your hosting account.

What now?

You’re starting to see how PHP programs can work with databases. Let’s look at DogToys and DogRock again. We’ll go through all of their screens, and see how they fit together.


How to...

Lessons

User login

Log in problems? Try here


Dogs