I have a PHP WebService type SOAP in Azure and I'm using MySQL in App. The database is up and running ... but I can not execute a simple Query! Where is the error?
<?php
$connectstr_dbhost = '';
$connectstr_dbname = '';
$connectstr_dbusername = '';
$connectstr_dbpassword = '';
foreach ($_SERVER as $key => $value) {
if (strpos($key, "MYSQLCONNSTR_localdb") !== 0) {
continue;
}
$connectstr_dbhost = preg_replace("/^.*Data Source=(.+?);.*$/", "\1", $value);
$connectstr_dbname = preg_replace("/^.*Database=(.+?);.*$/", "\1", $value);
$connectstr_dbusername = preg_replace("/^.*User Id=(.+?);.*$/", "\1", $value);
$connectstr_dbpassword = preg_replace("/^.*Password=(.+?)$/", "\1", $value);
}
$link = mysqli_connect($connectstr_dbhost, $connectstr_dbusername, $connectstr_dbpassword,$connectstr_dbname);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "<br> Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "<br> Host information: " . mysqli_get_host_info($link) . PHP_EOL;
echo "<br> host information: " .$connectstr_dbhost;
echo "<br> dname information: " .$connectstr_dbname;
echo "<br> user information: " .$connectstr_dbusername;
echo "<br> pass information: " .$connectstr_dbpassword;
echo "<br>";
//query para selecionar todos os produtos
$sql = "select * from produtos";
$result= mysqli_query($sql,$link);
var_dump($result);
$produtos = array();
$linha = mysql_fetch_assoc($result);
$total = mysql_num_rows($result);
$i =0;
if($total > 0) {
do {
echo "<br>".$linha['codigo']." ".$linha['nome']."<br>";
$produtos[$i] = $linha;
$i++;
}while($linha = mysql_fetch_assoc($result));
}
return $produtos;
mysqli_close($link);
?>
BankData: