PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of henryi   PHP-MYSQL-MSSQL   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example of this class
Class: PHP-MYSQL-MSSQL
The Class for PHP2MYSQL or PHP2MSSQL
Author: By
Last change: The new example of the new class.
Date: 21 years ago
Size: 5,257 bytes
 

Contents

Class file image Download
<?php
#####################################################################
# File Name : demo.php
# Author : Henry Chen
# Last Modify : May 08,2003 (GMT+8)
# License : GPL
# Contact Info
# E-Mail : [email protected]
# ICQ : 55490755
# AIM : wowphp
# YIM : [email protected]
#####################################################################
# This script include two parts
# 1. Create Table
# 2. Class demo
#####################################################################

# Variables
   
$tb_name = "demo";
    include(
"setting.inc.php");
   
$sql = new mod_db();

# Create Table
   
$string = "CREATE TABLE IF NOT EXISTS `$tb_name`(";
   
$string .= "`student_id` INT( 8 ) NOT NULL AUTO_INCREMENT,";
   
$string .= "`student_name` VARCHAR( 8 ) NOT NULL ,";
   
$string .= "`student_score` INT( 3 ) NOT NULL ,";
   
$string .= "PRIMARY KEY ( `student_id` ) ";
   
$string .= ");";

   
$sql->query("$string");

# Insert data to table
    # function insert($tb_name,$cols,$val,$astriction)

    # Data 1
       
$ins_string = "'','Henry','99'";
       
$sql->insert("$tb_name","","$ins_string","");
   
# Data 2
       
$ins_string = "'','Frank','50'";
       
$sql->insert("$tb_name","","$ins_string","");
   
# Data 3
       
$ins_string = "'','Derek','80'";
       
$sql->insert("$tb_name","","$ins_string","");

# Data Count
    # function nums($string="",$qid="")
    # function query($string)

    // Method 1 : String
       
$numb1 = $sql->nums("select * from $tb_name");
        echo
"Count : String<br>------------------------------------------<br>";
        echo
"Method 1 = ".$numb1."<br><br><br>";
   
// Method 2 :
       
$numb_query = $sql->query("select * from $tb_name");
       
$numb2 = $sql->nums('',$numb_query);
        echo
"Count : Query + Num<br>------------------------------------------<br>";
        echo
"Method 2 = ".$numb2."<br><br><br>";

# Get data detail information
    # function nums($string="",$qid="")
    # function objects($string="",$qid="")

    // Method 1 : String
       
$obj1 = $sql->objects("select * from $tb_name where student_name='Henry'");
        echo
"Get data : String<br>------------------------------------------<br>";
        echo
"Student ID = ".$obj1->student_id."<br>";
        echo
"Student Name = ".$obj1->student_name."<br>";
        echo
"Student Scroe = ".$obj1->student_score."<br><br><br>";

   
// Method 2
       
$obj_query = $sql->query("select * from $tb_name where student_name='Henry'");
       
$obj2 = $sql->objects('',$obj_query);
        echo
"Get data : Query + Object<br>------------------------------------------<br>";
        echo
"Student ID = ".$obj2->student_id."<br>";
        echo
"Student Name = ".$obj2->student_name."<br>";
        echo
"Student Scroe = ".$obj2->student_score."<br><br><br>";

   
// Method 3 : Loop
       
$obj_query = $sql->query("select * from $tb_name");

        echo
"Get data : Loop<br>------------------------------------------<br>";
        while(
$obj3 = $sql->objects('',$obj_query)){
            echo
"Student ID = ".$obj3->student_id."&nbsp;&nbsp;";
            echo
"Student Name = ".$obj3->student_name."&nbsp;&nbsp;";
            echo
"Student Scroe = ".$obj3->student_score."<br>";
        }
        echo
"<br><br><br>";

# Update data
    # function update($tb_name,$string,$astriction)
       
        // Data before update
           
$bu = $sql->objects("select * from $tb_name where student_name='Frank'");
            echo
"Data before update<br>------------------------------------------<br>";
            echo
"Student ID = ".$bu->student_id."&nbsp;&nbsp;";
            echo
"Student name = ".$bu->student_name."&nbsp;&nbsp;";
            echo
"Student score = ".$bu->student_score."<br><br><br>";

       
// Update data
           
$update_str = "student_score='70'";
           
$sql->update("$tb_name","$update_str","student_name='Frank'");
       
       
// Data after update
           
$au = $sql->objects("select * from $tb_name where student_name='Frank'");
            echo
"Data after update<br>------------------------------------------<br>";
            echo
"Student ID = ".$au->student_id."&nbsp;&nbsp;";
            echo
"Student name = ".$au->student_name."&nbsp;&nbsp;";
            echo
"Student score = ".$au->student_score."<br><br><br>";
       
# Delete data
    # function del($tb_name,$astriction)

        // Data before delete
           
$bd_query = $sql->query("select * from $tb_name");
            echo
"Data before delete<br>------------------------------------------<br>";
            while(
$bd = $sql->objects('',$bd_query)){
                echo
"Student ID = ".$bd->student_id."&nbsp;&nbsp;";
                echo
"Student Name = ".$bd->student_name."&nbsp;&nbsp;";
                echo
"Student Scroe = ".$bd->student_score."<br>";
            }
            echo
"<br><br><br>";

       
// Delete Data
           
$sql->del("$tb_name","student_name='Frank'");

       
// Data after delete
           
$ad_query = $sql->query("select * from $tb_name");
            echo
"Data after delete<br>------------------------------------------<br>";
            while(
$ad = $sql->objects('',$ad_query)){
                echo
"Student ID = ".$ad->student_id."&nbsp;&nbsp;";
                echo
"Student Name = ".$ad->student_name."&nbsp;&nbsp;";
                echo
"Student Scroe = ".$ad->student_score."<br><br><br>";
            }
            echo
"<br><br><br>";

# Page cute
   
    // Query
   
$list_string = "select * from $tb_name";
   
$list_query = $sql->query($sql->page_cut($list_string,$nowpage));

   
// Count
   
$list_num = $sql->nums("$list_string");

   
// Show pagecut
   
echo($sql->show_page_cut('',$list_num,"num=$num"));
?>