PHP Classes
Icontem

File: example.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jeff Williams  >  Remote MySQL Query  >  example.php  
File: example.php
Role: Example script
Content type: text/plain
Description: Example file
Class: Remote MySQL Query
Execute remote MySQL queries across the Web
 

Contents

Class file image Download
<?php
// This class requires that you place the file
// remote_query_server.php on the remote server

include('remotequery.class.php');

// Create the RemoteQuery object
// The URL should point to the remote_query_server.php file
// on the remote server. The security code is set in that file.
// The database settings here are the same as the MySQL
// database on the remote server box.
$url 'http://yourserver.com/remote_query_server.php';

$query = new RemoteQuery($url'pass123''database''localhost''dbuser''dbpassword');

// Execute the remote query
$sql "SELECT * FROM table";
$array $query->executeQuery($sql);

// Check for an error
if ($query->error) exit($query->error);

// Check for records (if this was a SELECT query)
if ($query->rowCount == 0) {

    echo 
'No records returned';

} else {

    
// Display the return array
    
echo "<pre>\n";
    echo 
"Returned Row Count: " $query->rowCount "\n";
    echo 
"Timed Microseconds: " $query->duration "\n";
    echo 
"\n";

    
print_r($array);

    
// Access data using this syntax:
    // $array[$row_number]['FieldName'];
    // NOTE: Row number starts with 0

    
echo "</pre>";
}

/* Additional Notes:

The remotequery.class.php client class simply converts XML data retruned
from the server into an easy to use array and contains a few extra parameters
(like row count, timer, and SQL). You can use other languages to convert the
XML returned from the remote_query_server.php file located on the server.

The actual returned XML (that is used in marshalling) from the
remote_query_server.php file (on the remote server) looks like this:
-----------------------------------------------------------------------------
<?xml version="1.0" ?>
<root rows="2" microseconds="0.00050081346729258" query="SELECT * FROM Test">
    <row index="1">
        <FirstName>John</FirstName>
        <LastName>Doe</LastName>
        <ZipCode>12345</ZipCode>
        <Phone>555-1212</Phone>
    </row>
    <row index="2">
        <FirstName>Jane</FirstName>
        <LastName>Smith</LastName>
        <ZipCode>54321</ZipCode>
        <Phone>555-1212</Phone>
    </row>
</root>
-------------------------------------------------------------------------- */
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products