I have a SQL server host on Microsoft Azure, I tried to query some data from it on Visual Studio. It works, however, I just keep getting 500 error code when I try to query by PHP. Am I having anything wrong? Here is my code
try{
$conn = new PDO ( not shown for privacy reason );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}catch(PDOException $e){
header("Content-type: plain/text");
print($e->getMessage());
}
$name = $conn->quote($name);
$pw = $conn->quote($pw);
$account = $conn->query("SELECT [user]
FROM dbo.user_data
WHERE [user] LIKE $name AND [password] LIKE $pw");
return $account[0];
First, PDO::query — Executes an SQL statement, returning a result set as a PDOStatement object. $account[0] will result a fatal error "Cannot use object of type PDOStatement as array" So, you should do this after the code to access each row value as :
$account = $conn->query("SELECT [user]
FROM dbo.user_data
WHERE [user] LIKE $name AND [password] LIKE $pw");
foreach ($account as $row) {
print_r($row);
}
Hope this solves your problem. Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.