• home
  • forum
  • my
  • kt
  • download
  • PHP MySQL tutorial

    Author: 2008-08-28 09:19:13 From:

    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.

     

    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. phpinfo();
    3. ?>
    PHP F1

    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.  
    PHP F1

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (16)
      Date and Time (13)
      Development (19)
      Discussion Boards (8)
      E Commerce (8)
      Email Systems (13)
      Error Handling (7)
      File Manipulation (24)
      Flash and PHP (6)
      Form Processing (19)
      Guestbooks (12)
      Image Manipulation (21)
      Installing PHP (7)
      Introduction to PHP (23)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (53)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot