Skip to content Skip to sidebar Skip to footer

Symfony Connect With Windows Azure

I know it may sounds crazy, but i want to connect a symfony project with microsoft azure database connection. I have searched a lot to find the solution, but I did not find a singl

Solution 1:

When you create any service always had a notepad open:

So, when you created the SQL Server you type user and passowrd and then you create SQL Databases and then you choose a SQL Server to associate the new db.

With those things created you connect with PDO in this way:

try {   
    $conn = new PDO ( "sqlsrv:server = tcp:<SQL_SERVER>.database.windows.net,1433; Database = <SQL_DATABASE>", "<SQL_SERVER_USER>", "SQL_SERVER_USER_PASSWORD");
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}catch ( PDOException $e ) {
print( "Error connecting to SQL Server." );
die(print_r($e));
}

Where

  1. SQL_SERVER is the name of the SQL Server
  2. SQL_DATABASE is the name of the database associated to the SQL_SERVER
  3. SQL_SERVER_USER & SQL_SERVER_USER_PASSWORD are the user and password for the SQL_SERVER

In Symphony you must set the driver to pdo_sqlsrv and let Doctrine do his work

Get the connection string You can see your connection string going to the portal, then select your databse and then click "Show database connection strings" in the new panel you will see OBDC, PDFO... connection example code without the password

Change user password Go the the SQL server, then click in the top icon "reset password", change it.

Post a Comment for "Symfony Connect With Windows Azure"