Login   Register  
PHP Classes
elePHPant
Icontem

File: README.TXT

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mark Quah  >  MARK_MYSQL  >  README.TXT  >  Download  
File: README.TXT
Role: Documentation
Content type: text/plain
Description: Readme
Class: MARK_MYSQL
MySQL interface
Author: By
Last change:
Date: 2002-11-01 06:50
Size: 2,142 bytes
 

Contents

Class file image Download
Another unpolished class. Those take time to polish it up please do inform me.

This class has been used extensively in my web project and I really find that it is very much convenient to use.

This is the way to use it:
------------------------------------------------
INITIALIZATION:
    include_once "class_mysql.php";
    $my_db = new MYSQL("server", "user", "passwd", "database to use");
------------------------------------------------
DO A QUERY EXPECTING INPUT
    $stmt = "SELECT * ....";
    $status = $my_db->RunDB($stmt);
    if ($status != "OK") { echo "FAIL"; die; }
now the number of records retreived is stored in
    $no_rec = $my_db->no_rows;
to retrieve individual fields, say field name is "A", "B", C"
    for ($i = 0; $i < $no_rec; $i ++)   // record number
    {    $fieldA=$my_db->row[$i]['A'];
         $fieldA=$my_db->row[$i]['B'];
         $fieldA=$my_db->row[$i]['C'];
         ... do your processing.
    }
IF you don't know about the field names, here's what you can do:
    for ($j = 0; $j < $my_db->no_fields; $j ++)
       $field_name[j] = $my_db->field[$j];
no_fields contains no of fields within a record. each field name is contained in $my_db->field[$j]

---------------------------------------------------
DO A SQL STATEMENT NOT EXPECTING OUTPUT

If you do a insert or update, you do not expect the array $my_db->row to be filled, so you specify a 0 after the RunDB statement:
    
      $stmt="INSERT INTO table (a,b,c) VALUES(1,2,3);";
      $status = $my_db->RunDB($stmt, 0);
      if ($status != "OK") { echo "FAILED: $status"; die; }

------------------------------------------------------
USE THE BUILT IN HTML OUTPUT

Pretty but seldom used function. This is for me to displayed an unknown SQL table data.

    $status = $my_db->RunDB("select * from user;");
    if ($status != "OK")
    {   echo "<HR>DB Error: $status.<HR>";
        die;
    }
    $mysql->ShowHTML("table_header","row header","cell header");

The HTML output will be something like:
   <TABLE table_header>
   <TR row_header>
   <TD cell_header> value ....