PHP Classes

File: ContainerExample.inc.php

Recommend this page to a friend!
  Packages of Cornelius Bolten   mysqlQueryContainer   ContainerExample.inc.php   Download  
File: ContainerExample.inc.php
Role: Example script
Content type: text/plain
Description: example-script how to use this package
Class: mysqlQueryContainer
Multi-connection MySQL container
Author: By
Last change: added mysql_connect() as alternative connect-method.
use
$myContainer = new mysqlquery("pconnect");
or
$myContainer = new mysqlquery("connect");
to switch between connect-methods
Date: 22 years ago
Size: 1,724 bytes
 

Contents

Class file image Download
<?php

    /**
    *    $RCSfile: example.php,v $
    *    @author     $Author: Cornelius Bolten $
    *    @version    $Revision: 1.2 $
    *
    *
    *    @description:
    *        - this is the example-file for mysqlQueryContainer by 
    *          Cornelius Bolten
    *
    *    so now..here we go!
    *    
    **/
    
    require_once("mysqlQuery.inc.php");
    
    /**
    *    create MySQL-Container named "connection1" and another one
    *    named "connection2"
    */    
    $myContainer    =    new mysqlquery("pconnect");
    if(!$myContainer->addNewConnection("connection1","host1","databaseY","user","password",3306))
        echo("error: ".$myContainer->containerError);
    if(!$myContainer->addNewConnection("connection2","host2","databaseX","otheruser","otherpassword"))
        echo("error: ".$myContainer->containerError);
        
    /**
    *    open both database-connections
    */    
    if(!$myContainer->openConnection("connection1"))
        echo("error: ".$myContainer->containerError);
    if(!$myContainer->openConnection("connection2"))
        echo("error: ".$myContainer->containerError);
    
    /**
    *    execute an SELECT statement on connection 1
    */
    if(!$myData = $myContainer->executeSelect("connection1","SELECT * FROM `Table1` LIMIT 0, 30")) {
        echo("error: ".$myContainer->sqlError);
    } else {
        echo "<bR>query executed correct";
    }
    
    /**
    *    and another execute on connection 2
    */    
    if(!$myData = $myContainer->executeSelect("connection2","SELECT * FROM `Table1` LIMIT 0, 30")) {
        echo("error: ".$myContainer->sqlError);
    } else {
        echo "<br>query executed correct";
    }    
            
    /**
    *    finally close both connections and flush container.
    */            
    $myContainer->closeConnection("connection1");
    $myContainer->closeConnection("connection2");
    $myContainer->flushConnectionContainer();
?>