Location: PHPKode > scripts > Remote MySQL Query > remote-mysql-query/example.php
// 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 = '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";


    // 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">
-------------------------------------------------------------------------- */
Return current item: Remote MySQL Query