Location: PHPKode > scripts > Remote MySQL Query > remote-mysql-query/example.php
<?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>
-------------------------------------------------------------------------- */
?>
Return current item: Remote MySQL Query