K
K
kmx2014-02-23 18:44:25
PHP
kmx, 2014-02-23 18:44:25

How to connect and read data from SQL database in Windows Azure?

There is a database in Azure, it is necessary to display some information from this database on a third-party site.
I added the server IP to the rules, code of this kind does not work:
(this is how Azure advises connecting to the database)

try {
   $conn = new PDO ( "sqlsrv:server = tcp:433434dfs.database.windows.net,1433; Database = Имябазы", "логин", "пароль");
   $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
   }
   catch ( PDOException $e ) {
   print( "Error connecting to SQL Server." );
   die(print_r($e));
   }
   
//Чтение из базы   
$sql_select = "SELECT * FROM Lalala";
$stmt = $conn->query($sql_select);
$feedback = $stmt->fetchAll(); 
if(count($feedback) > 0) {
    foreach($feedback as $feedbacks) {
        echo "Date: ".$feedbacks['date'].", ";
        echo "Name: ".$feedbacks['name'].", ";
    }
} else {
    echo "<h3>Пусто в базе о_О</h3>";
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2014-02-23
@kmx

You need to install the extension for PDO
It seems that you can get it from here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question