PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Patrik  >  MySQL Comunicator  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: MySQL Comunicator
Execute MySQL queries from lists of parameters
Author: By
Last change:
Date: 3 years ago
Size: 2,689 bytes
 

Contents

Class file image Download
<?php

define
('DATABASE_HOST', 'loalhost'); // Host to MySQL Database
define('DATABASE_USER', 'root'); // User to login
define('DATABASE_PASSWORD', ''); // Password to login
define('DATABASE_DATABASE', 'test'); // Database name
include('MySQL.php');



   
### SPF_DB::Select ###
   
SPF_DB::Select("....SQL....", $arg) or SPF_DB::Select("....SQL....", array($arg, $arg))
   
       
# EXAMPLE 1 #
       
SPF_DB::Select("SELECT * FROM user WHERE login='%s' AND password='%s'", array($login, $password));
       
SPF_DB::Select("SELECT * FROM user WHERE id='%s'", $id);
       
       
       
# EXAMPLE 2 #
       
SPF_DB::Select("SELECT * FROM user WHERE id='%s'");
        while(
$tmp = SPF_DB::Data()) {
            echo
$tmp['id']. '->'. $tmp['login']; // Show user id and login
       
}
       
       
       
# EXAMPLE 3 #
       
$sql = SPF_DB::Select("SELECT * FROM user WHERE id='%s'");
        while(
$tmp = SPF_DB::Data($sql)) {
            echo
$tmp['id']. '->'. $tmp['login']; // Show user id and login
       
}
       
       
       
# EXAMPLE 4 #
       
$sql = SPF_DB::Select("SELECT * FROM user WHERE id='%s'");
        foreach(
SPF_DB::Data('id') as $v) {
            echo
$v; // Show user id
       
}
       
       
       
# EXAMPLE 5 #
       
$sql = SPF_DB::Select("SELECT * FROM user WHERE id='%s'"); // We must set $sql
       
while($tmp = SPF_DB::Data($sql)) { // use $sql
           
SPF_DB::Select("...");
           
           
/*
                * IMPORTANT !!!
                * If you use another command you must define first SELECT !!!
            */
       
}
       
       
       
# EXAMPLE 6 #
       
SPF_DB::Select("SELECT * FROM user WHERE id='%s'");
       
SPF_DB::fullData(); // return all rows as array
       
       
        # SELECT NUM #
       
SPF_DB::Num(); // return num rows
       
       
       
    ### SPF_DB::Insert ###
   
SPF_DB::Insert('table_name', array('row_name' => 'value')); // basic format
   
SPF_DB::Insert('table_name', array('row_name' => 'value'), TRUE); // basic format + DELAYED (For MyISAM table only)
   
SPF_DB::Insert('table_name', array('row_name' => 'value'), FALSE, TRUE); // basic format + ON DUPLICATE update rows
   
   
   
    ### SPF_DB::Replace ###
   
SPF_DB::Insert('table_name', array('row_name' => 'value'));
   
   
   
   
### SPF_DB::Update ###
   
SPF_DB::Update('table_name', array('row_name' => 'value')); // for all rows
   
        # EXAMPLE 1 #
       
SPF_DB::Update('table_name', array('row_name' => 'value'), array('1_condition_row' => 'value', '2_condition_row' => 'value'));
       
       
equals
       
        SPF_DB
::Update('table_name', array('row_name' => 'value'), "1_condition_row='value' AND 2_condition_row='value'");
       
       
       
# EXAMPLE 2 #
       
SPF_DB::Update('table_name', array('row_name' => 'value'), "row1='value' OR row2='value'");

       
       
# LAST_INSERT_ID #
       
SPF_DB::ID();
       
   

   
### SPF_DB::Delete ###
   
SPF_DB::Delete('table_name', array('1_condition_row' => 'value', '2_condition_row' => 'value'));
   
   
   
   
### OTHER ###
       
SPF_DB::Affected();