PHP MySQL tutorial


Home - Tutorials - Databases

In this PHP MySQL tutorial I will show you how to use basic database manipulation features in PHP.

Tutorial info:


Name:PHP MySQL tutorial
Total steps:5
Category:Databases
Level:Beginner

Bookmark PHP MySQL tutorial



Bookmark and Share

Step 1 - PHP MySQL introduction


PHP MySQL tutorial

As you know by the help of PHP you can create dynamic website content. The dynamic content doesn't necessary require a database, however in most cases you have/need one. All of the content management systems, blogs or only a simple form processor use database. In the PHP world the most commonly used database is MySQL. So in the next section I will focus on how to use PHP and MySQL to create dynamic content. In this tutorial I will focus only PHP MySQL usage basics, and I suppose you have already an  installed and properly configured system supporting both PHP and MySQL. You can always find reliable hosting at the top web hosting companies.

 

Check your configuration

To avoid any problem in the later steps you should check your actual configuration. To do this you need to create a simple Php file which calls the function phpinfo(). The file is really simple:

Code:
  1. <?php
  2. ?>

If you open this site then you can check how your system is configured. The most important in this case the MySQL section of the output. It should look like something like this:

php mysql

If you have no MySQL section then it means that MySQL access is not possible with the actual server settings. Ask your system administrator to configure it for you. (Later I plan to write a tutorial which guide you through the necessary steps.) 

 

Creating a test database

In this tutorial I will use a MySQL database named test with a single table called users. Below you can find the sql code which creates the database, the table and inserts some default data.

Code:
  1. CREATE DATABASE if NOT EXISTS `test`;
  2.  
  3. USE test;
  4.  
  5. CREATE TABLE `users` (
  6. `id` INT(11) NOT NULL AUTO_INCREMENT,
  7. `name` VARCHAR(100) DEFAULT NULL,
  8. `city` VARCHAR(100) DEFAULT NULL,
  9. `web` VARCHAR(100) DEFAULT NULL,
  10. `age` SMALLINT(6) DEFAULT NULL,
  11. PRIMARY KEY (`id`)
  12. ) ENGINE=INNODB DEFAULT CHARSET=latin1;
  13.  
  14.  
  15. INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (1,'Mike','New York','www.mike.com',25);
  16. INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (2,'John','Dallas','www.john.com',37);
  17. INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (3,'Anna','London','www.anna.com',24);
  18. INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (4,'David','Oxford','www.david.com',19);
  19. INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (5,'Julia','New York','www.julia.com',20);
  20.  

 

Ensure your notebook is working at optimum level by using an efficient notebook cooler.





Next Step of PHP MySQL tutorial


Tags: php mysql tutorial, php mysql, php database, php, mysql, tutorial



Follow phpf1 on Twitter




F1 Site Family
AJAX F1
CSS F1
Database F1
Flash F1
HTML F1
Java F1
JavaScript F1
PhotoShop F1
PHP F1
Scripts F1
Tutorial F1
Windows F1

Total time: 0.0358