gpt4 book ai didi

php - Web 服务不适用于 mysql

转载 作者:行者123 更新时间:2023-11-29 02:52:24 27 4
gpt4 key购买 nike

社区,我正在用 PHP 做一个 Web 服务,我需要在 mysql 中获取数据库信息。

我不明白的是,如果我将所有代码都传递到一个文件中(例如传递到 client.php 中),这可以正常工作,但是在这里分开两个文件不起作用,在 server.php 中无法进入 while 函数我在其中创建了一个包含 mysql 查询带来的所有信息的数组。

有人可以帮助我吗?

服务器.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();
?>

客户端.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);
}
?>

最佳答案

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

注意:

Warning These extensions were deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: mysqli_fetch_array() PDOStatement::fetch()

关于php - Web 服务不适用于 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34315234/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com