I'm trying to use a php script to query a mysql database, make a xml file with the data, then return it to be accessed in the c++ app. I will then be trying to edit the data returned in c++, like printing or truncating it. Right now all I have in my main function in c++ is
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
cout << system("C:/xampp/php/php E:/phpTest.php");
return 0;
}
my php script includes...
phpTest.pnp:
<?php
require_once("mysqli.php");
$connector = new Mysqli_connector();
$xmlTest = $connector->selectTest();
return $xmlTest;
?>
and mysqli.php:
<?php
class Mysqli_connector {
var $conn;
function __construct($db=array()) {
$default = array(
'host' => 'hostname',
'user' => 'username',
'pass' => 'password',
'db' => 'database'
);
$db = array_merge($default,$db);
$this->conn = mysqli_connect($db['host'],$db['user'],$db['pass'],$db['db'])
or die("Error connecting to database");
}
function __destruct() {
mysqli_close($this->conn);
}
function selectTest(){
$res = mysqli_query($this->conn,"select * from loginTest") or die("Error querying");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<Data>" . "\n";
$xml_output .= "field1" ."\t". "field2" ."\t". "field3" ."\t". "field4" ."\t". "field5";
$xml_output .= "\n";
for($x = 0; $x < mysqli_num_rows($res); $x++)
{
$row = mysqli_fetch_assoc($res);
$xml_output .= $row['field1'] . "\t";
$xml_output .= $row['field2'] . "\t";
$xml_output .= $row['field3'] . "\t";
$xml_output .= $row['field4'] . "\t";
$xml_output .= $row['field5'] . "\n";
}
return $xml_output;
}
}
?>
Using return
does seem to work when I return from mysqli.php, but then I cannot send it to the c++ app using the same return statement. Does anyone know the proper way to do that?