I'm trying to show some results using PDO. Until now I used mysqli_conect()
for the connection to the database. I guess the error is found by showing the results in the 'foreach ()' Someone would know how to correct the fault? Thanks in advance "
Code:
<?php
try {
$conn = new PDO("sqlsrv:server = tcp:name.database.windows.net,1344;
Database = my_db_name", "my_user_name", "my_password");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT Prod_Usu, Prod_Tit, Prod_Fec FROM productos");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach($result as $row) {
echo $row['Prod_Usu'] . " - " . $row['Prod_Tit'] . " - " .
$row['Prod_Fec'] . "<br>";
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>