PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Jeff Williams   Remote MySQL Query   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example file
Class: Remote MySQL Query
Execute remote MySQL queries across the Web
Author: By
Last change: Updated example
Date: 16 years ago
Size: 2,296 bytes


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


// 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 = '';

$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) {

'No records returned';

} else {

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


// 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">
    <row index="2">
-------------------------------------------------------------------------- */