社区,我正在使用PHP进行Web服务,我需要在mysql中提供数据库信息。
如果我将所有代码都传递到一个文件中(例如进入client.php)我不明白这个工作正常,但是在这两个文件中分隔不起作用,在server.php中没有输入到while函数我创建一个包含mysql查询带来的所有信息的数组。
有人可以帮助我吗?
server.php
<?php
//call library
//require_once ('config.php');
require_once ('lib/nusoap.php');
$servidor = '?';
$user = '?';
$pass = '?';
$base = '?';
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('get_message');
// create the function
function get_message($your_name)
{
if(!$your_name){
return new soap_fault('Client','','Put Your Name!');
}
$conexion = mysql_connect($servidor, $user,$pass);
mysql_select_db($base, $conexion);
$consulta = "SELECT * FROM ensayos_santa_laura where ENS_FECHA_MUESTREO > '2015-01-01' ";
$datos = mysql_query($consulta, $conexion);
$numDatos = @mysql_num_rows($datos);
$registro = array();
$contador = 1;
while($fetchrow = mysql_fetch_row($datos)){
$registro[$contador]['WS_NUMERO_MUESTRA'] = $fetchrow['2'];
$registro[$contador]['WS_FECHA_MUESTREO'] = $fetchrow['3'];
$registro[$contador]['WS_NUMERO_CERTIFICADO'] = $fetchrow['4'];
$registro[$contador]['WS_FECHA_ENSAYO'] = $fetchrow['5'];
$registro[$contador]['WS_NUMERO_GUIA'] = $fetchrow['6'];
$registro[$contador]['WS_EDAD'] = $fetchrow['7'];
$registro[$contador]['WS_DENSIDAD'] = $fetchrow['8'];
$registro[$contador]['WS_RESISTENCIA'] = $fetchrow['9'];
$registro[$contador]['WS_RT'] = $fetchrow['10'];
$registro[$contador]['WS_TIPO_HORMIGON'] = $fetchrow['11'];
$registro[$contador]['WS_NUMERO_CONTROL'] = $fetchrow['12'];
$registro[$contador]['WS_ASENTAMIENTO'] = $fetchrow['13'];
$registro[$contador]['WS_LINK'] = $fetchrow['14'];
$registro[$contador]['WS_ESTADO'] = $fetchrow['15'];
$registro[$contador]['WS_TIPO_PROBETA'] = $fetchrow['16'];
$registro[$contador]['WS_CODIGO_OBRA'] = $fetchrow['17'];
$registro[$contador]['WS_UBICACION_HORMIGON'] = $fetchrow['18'];
$contador++;
}
$cantidad = count($registro);
if($registro){
return $registro;
}else{
return 0;
}
}
// create HTTP listener
$server->service(file_get_contents("php://input"));
//$server->service($HTTP_RAW_POST_DATA);
exit();
?>
client.php
<?php
require_once ('config.php');
require_once ('lib/nusoap.php');
//Give it value at parameter
$param = array( 'your_name' => 'Monotosh Roy');
//Create object that referer a web services
$client = new nusoap_client('http://172.17.56.61/ws_santalaura/server.php');
//Call a function at server and send parameters too
$response = $client->call('get_message',$param);
//Process result
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode."</p>";
echo "String: ".$client->faultstring;
}
else
{
$xml = new DOMDocument();
$dateInfoElement = $xml->createElement("dateInformation");
foreach ($response as $key => $value) {
$xmlNode = $xml->createElement($key,$value);
$dateInfoElement->appendChild($xmlNode);
}
$xml->appendChild($dateInfoElement);
$header = "Content-Type:text/xml";
header($header);
print $xml->saveXML();
//echo var_dump($response);
}
?>
答案 0 :(得分:1)
如docs
中所示mysql_fetch_row — Get a result row as an enumerated array
相反,请尝试使用mysql_fetch_array:
mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both
注意:强>
警告这些扩展在PHP 5.5.0中已弃用,并已被删除 在PHP 7.0.0中。相反,MySQLi或PDO_MySQL扩展应该是 用过的。另请参阅MySQL:选择API指南和相关常见问题解答以获取更多信息 信息。该功能的替代方案包括: mysqli_fetch_array()PDOStatement :: fetch()