PHP Classes
elePHPant
Icontem

File: Example

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Levert Cyril  >  Simple and Speed MySQL Layer  >  Example  >  Download  
File: Example
Role: Example script
Content type: text/plain
Description: Example
Class: Simple and Speed MySQL Layer
MySQL database access wrapper
Author: By
Last change:
Date: 5 years ago
Size: 2,597 bytes
 

Contents

Class file image Download
<?php
/************************************************************************/
/* Simple and Speed SQL Layer MySQL */
/* ================================ */
/* Write by Cyril Levert */
/* Copyright (c) 2009 */
/* This layer is used in : */
/* Blog project : http://www.php-minimus.org */
/* CMS project : http://www.php-maximus.org */
/* dev@php-minimus.org */
/* */
/* This program is free software. */
/************************************************************************/

/** define your database vars */
define_once('DBHOST', 'localhost');
define_once('DBUNAME', 'db_uname');
define_once('DBNAME', 'db_name');
define_once('DBPASS', 'db_pass');

/** load sql layer */
( is_file( 'MySQL.php' ) ) ? include_once( 'MySQL.php' ) : die('Code '.__LINE__.': sorry, controle your include !');

/** open no persistante mysql connection */
$db = new sql_db( DBHOST, DBUNAME, DBPASS, DBNAME, false);
if( empty(
$db->db_connect_id ) )
    die(
'Error mysql !');


/** OR open persistante mysql connection */
$db = new sql_db( DBHOST, DBUNAME, DBPASS, DBNAME, true);
if( empty(
$db->db_connect_id ) )
    die(
'Error mysql !');



/** example insert */
$db->query("INSERT INTO `table` ( `id`, `name`, `date` ) VALUES ( NULL, 'test', now() )");

/** example update */
$db->query("UPDATE `table` SET `name`='$name', `date`=now() WHERE `id`='$id' ");

/** example object - simple var */
$object = $db->get_object("SELECT `name` FROM `table` WHERE `id`= 1 ");
echo
$object->name ;

/** example array - simple var */
$row = $db->get_row("SELECT `name` FROM `table` WHERE `id`= 1 ");
echo
$row['name'] ;

/** example object - multiple vars */
if ( $sql = $db->get_list_object('SELECT `tag` FROM `table` GROUP BY `tag` ORDER BY `id` DESC LIMIT 30') ) {
    foreach (
$sql as $objects ) {
        echo
$objects->tag .'<br/>';
    }
}

/** example array - multiple vars */
if ( $sql = $db->get_list_row('SELECT `tag` FROM `table` GROUP BY `tag` ORDER BY `id` DESC LIMIT 30') ) {
    foreach (
$sql as $rows ) {
        echo
$rows['tag'] .'<br/>';
    }
}

/** example number of vars */
$num = $db->get_num("SELECT `id` FROM `table` WHERE `id`= 1 ");
echo
$num ;


/** close mysql connection */
$db->sql_close();