Hi,
I'm writing a method to export the contents of a mysql table in a text file via a web service nusoap.
the method in my web server:
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'service';
$fichier = 'C:\Users\Desktop\test\fichier.txt';
$csv_terminated = "\n";
$csv_separator = ";";
$csv_enclosed = '"';
$csv_escaped = "\\";
$db1=new PDO('mysql:host=localhost;dbname=service','root','');
$sql_query ="SELECT * FROM myusers";
$result = $db1->query($sql_query);
$fields_cnt =$result->columnCount();
$schema_insert = '';
for ($i = 0; $i < $fields_cnt; $i++)
{
$col = $result->getColumnMeta($i);
$l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
stripslashes($col['name'])) . $csv_enclosed;
$schema_insert .= $l;
$schema_insert .= $csv_separator;
}
$out = trim(substr($schema_insert, 0, -1));
$out .= $csv_terminated;
while ($row = $result->fetch())
{
$schema_insert = '';
for ($j = 0; $j < $fields_cnt; $j++)
{
if ($row[$j] == '0' || $row[$j] != '')
{
if ($csv_enclosed == '')
{
$schema_insert .= $row[$j];
} else
{
$schema_insert .= $csv_enclosed .
str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
}
} else
{
$schema_insert .= '';
}
if ($j < $fields_cnt - 1)
{
$schema_insert .= $csv_separator;
}
}
$out .= $schema_insert;
$out .= $csv_terminated;
}
calling the method:
<?php
error_reporting(E_ALL);
require_once('lib/nusoap.php');
$client = new nusoap_client('http://localhost/testajout/server.php');
$res=$client->call('exportf');
print_r($res);
?>
the file was not created and no errors are displayed but I test the code without putting it in a function, it works. I think there is a mistake on the calling method or the register method.
the register code:
<pre lang="PHP">$server->register('exportf',array('return'=>'xsd:string'));
But I am unsure on what the return type should be if not a string? I am thinking of using a string.
What I have tried:
the file was not created and no errors are displayed.