本文介绍了通过nusoap Web服务在文本文件中导出mysql表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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';
//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
calling the method:
<?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);
?>
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.
推荐答案
这篇关于通过nusoap Web服务在文本文件中导出mysql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!