|
 |
|
กรุณาช่วยแนะนำการใช้ php ทำ web service ต้องการดึงข้อมูลจากฐานข้อมูล mysql โดยใช้ Nusoap |
|
 |
|
|
 |
 |
|
ผมลองเขียนดูแล้วนะคับ ส่วนของเซิฟเวอร์ server_book
Code (PHP)
<?
//call library
require_once ('lib/nusoap.php');
//using soap_server to create server object
$server = new soap_server;
$server->configureWSDL('server_bookwsdl', 'urn:server_bookwsdl');
//register a function that works on server
$server->register('getallbook');
// create the function
function getallbook()
{
$conn = mysql_connect('localhost','root','1234');
mysql_select_db('testdb', $conn);
$sql = "SELECT * FROM book";
$q = mysql_query($sql);
while($r = mysql_fetch_array($q)){
$items[] = array('cd'=>$r['cd'],
'title'=>$r['title'],
'author'=>$r['author'],
'publisher'=>$r['publisher']);
}
return $items;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
และ client_book
Code (PHP)
<?
require_once ('lib/nusoap.php');
$client = new nusoap_client('http://localhost/test/nusoap/server_book.php?wsdl',true);
$response = $client->call('getallbook');
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode.")</p>";
echo "String: ".$client->faultstring;
}
else
{
$r = $response;
$count = count($r);
?>
<table border="1">
<tr>
<th>Code</th>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
</tr>
<?
for($i=0;$i<=$count-1;$i++){
?>
<tr>
<td><?=$r[$i]['cd']?></td>
<td><?=$r[$i]['title']?></td>
<td><?=$r[$i]['author']?></td>
<td><?=$r[$i]['publisher']?></td>
</tr>
<?
}
?>
</table>
<?
}
?>
รัน client_book ออกมาได้หน้าเปล่า ๆ ช่วยแนะนำหน่อยนะครับ
|
 |
 |
 |
 |
Date :
2011-01-15 21:45:53 |
By :
nanahara13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยด้วยคร๊าฟฟฟฟ...
|
 |
 |
 |
 |
Date :
2011-02-04 20:43:32 |
By :
nanahara13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|