Thursday, January 10, 2008

PHP commands to connect with MySQL

PHP and MySQL class just end over a 3 day duration. The syllabus covers the basic PHP command structures. This included variable usage, loops, conditional, user defined functions, pre-defined functions and database connectivity. A quick way to learn connectivity with MySQL is to already be familiar with SQL and relational database.

What is there to know about the database? I have a checklist below for learners to use
  1. Database
    1. Creating
    2. Deleting
    3. Selecting/Using a database
  2. Field types and their use
    1. Numerical - int, float
    2. Strings - char, varchar, text
    3. Time - date, timestamp
  3. Tables
    1. Creating
    2. Deleting
    3. Altering tables
  4. Records
    1. Inserting records
    2. Deleting records
    3. Editing records
    4. Retrieving records

Once the SQL syntax is known, the next step is to use PHP to execute the SQL commands on the MySQL database server. Among the basic commands that can be use is listed below:

  1. mysql_connect( ) - Open connection to a MySQL database server
    1. Description: returns FALSE if fail
      resource mysql_connect ([ string $server [, string $username [, string $password [, bool $new_link [, int $client_flags ]]]]] )
  2. mysql_query( ) - Send SQL commands to MySQL database server
    1. Description: returns FALSE on error
      resource mysql_query ( string $query [, resource $link_identifier ] )
  3. mysql_select_db( ) - Determine which database name to use on the MySQL database server
    1. Description: returns TRUE or FALSE
      bool mysql_select_db ( string $database_name [, resource $link_identifier ] )
  4. mysql_fetch_array( ) - Retrieve a record as an array
    1. Description: returns FALSE if no more records
      array mysql_fetch_array ( resource $result [, int $result_type ] )
  5. mysql_close( ) - Close a MySQL database connection
    1. Description: returns TRUE of FALSE
      bool mysql_close ([ resource $link_identifier ] )

That is all for now. I will write more in coming postings on PHP use with MySQL.

No comments: