|
|
|
PHP SQL Server PDO - ปัญหา call to a member function fetch() on a non-object แก้ไม่ตก |
|
|
|
|
|
|
|
มันหาฟังก์ชั่น fetch ไม่เจอครับ
|
|
|
|
|
Date :
2014-01-25 16:06:52 |
By :
deawx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
if (isset($_POST['stopbtn']))
{
$stop = $_POST['stopbtn'];
$SQL = $odb -> prepare("UPDATE `logs` SET `stopped` = 1 WHERE `id` = :id");
$SQL -> execute(array(':id' => $stop));
$SQLSelect = $odb -> prepare("SELECT * FROM `logs` WHERE `id` = :id");
$SQLSelect -> execute(array(':id' => $stop));
while ($show = $SQLSelect -> fetch(PDO::FETCH_ASSOC))
{
$host = $show['ip'];
$port = $show['port'];
$time = $show['time'];
$method = $show['method'];
}
$SQLSelectAPI = $odb -> query("SELECT `api` FROM `API` ORDER BY `id` DESC");
while ($show = $SQLSelectAPI -> fetch(PDO::FETCH_ASSOC))
{
$arrayFind = array('[host]', '[port]', '[time]', '[method]');
$arrayReplace = array($host, $port, $time, $method);
$APILink = $show['api'];
$APILink = str_replace($arrayFind, $arrayReplace, $APILink);
$stopcommand = "&action=stop";
$stopapi = $APILink . $stopcommand;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $stopapi);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_exec($ch);
curl_close($ch);
}
|
|
|
|
|
Date :
2014-01-25 17:52:21 |
By :
TacioSoft |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใช้ fetchAll ครับ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & Windows Azure (SQL Azure)</title>
</head>
<body>
<?
$serverName = "tcp:bc6hela9fr.database.windows.net,1433";
$userName = 'thaicreate-user@bc6hela9fr';
$userPassword = 'password@123';
$dbName = "thaicreate-db";
$conn = new PDO("sqlsrv:server=$serverName ; Database = $dbName", $userName, $userPassword);
$strSQL = "SELECT * FROM customer";
$stmt = $conn->prepare($strSQL);
$stmt->execute();
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
$arrValues = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($arrValues as $result){
?>
<tr>
<td><div align="center"><?=$result["CustomerID"];?></div></td>
<td><?=$result["Name"];?></td>
<td><?=$result["Email"];?></td>
<td><div align="center"><?=$result["CountryCode"];?></div></td>
<td align="right"><?=$result["Budget"];?></td>
<td align="right"><?=$result["Used"];?></td>
</tr>
<?
}
?>
</table>
<?
$conn = null;
?>
</body>
</html>
|
|
|
|
|
Date :
2014-01-26 07:49:12 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|