Click here to Skip to main content
15,899,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

C#
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:


PHP
 $host = 'localhost';
$user = 'root';
$pass = '';
$db = 'service';
$fichier = 'C:\Users\Desktop\test\fichier.txt';

//format du CSV
$csv_terminated = "\n";
$csv_separator = ";";
$csv_enclosed = '"';
$csv_escaped = "\\";

// requête MySQL


// connexion à la base de données

    $db1=new PDO('mysql:host=localhost;dbname=service','root','');
    $sql_query ="SELECT * FROM myusers";

// exécute la commande
$result = $db1->query($sql_query);
$fields_cnt =$result->columnCount();


$schema_insert = '';

for ($i = 0; $i < $fields_cnt; $i++)
{
    $col = $result->getColumnMeta($i);
    //$columns[] = $col['name'];
    $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
stripslashes($col['name'])) . $csv_enclosed;
    $schema_insert .= $l;
    $schema_insert .= $csv_separator;
} // fin for

$out = trim(substr($schema_insert, 0, -1));
$out .= $csv_terminated;

// Format des données
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;
}
    } // fin for

    $out .= $schema_insert;
    $out .= $csv_terminated;
} // fin while

C#
calling the method:

PHP
 <?php
 error_reporting(E_ALL);
     // Pull in the NuSOAP code
    require_once('lib/nusoap.php');
    // Create the client instance
    $client = new nusoap_client('http://localhost/testajout/server.php');
    $res=$client->call('exportf');
    print_r($res);

?>

C#
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.
Posted
Comments
Mohibur Rashid 4-Apr-16 22:31pm    
You didn't echo or print your $out

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900