1

I am very new to SQL server ( 2005 to be exact ) but have been given a backup of a database (in .bak format) which i need to query. My issue lies with this as I have no idea how to set it up so I can query the database from PHP.

I am using a mac, with apache set up, PHP with an MSSQL extension. Also although I have a mac, I am currently using parallels to use Microsoft SQL server Management studio express so that I can restore the database from the .bak file and I can even successfully query the database...

My issue therefore, is I am lost as where to go from here...? How can I have this database accessible (locally on this machine) so that I can connect to it from php and arrange the results.

0

3 Answers 3

1

If SQL Server is setup with Parallels, I'm assuming you'll need to be sure it is accepting TCP connections. Here are docs to turn on TCP. From PHP the connection is quite simple:

$link = mssql_connect('localhost', 'username', 'password');
2
  • hmm do i not have to do anything extra to set up the server? I haven't set up a username or password in SQL server management for any connections etc.. and thanks for the php connection, I figured that cause I did something similar for a MYSQL one I did a year ago.
    – Didier
    Jul 3, 2011 at 17:59
  • You will need to create a login to your database. There are many documents out there detailing this process. Note, you want a SQL login and not a Trusted Connection. Here's one to get you started. quackit.com/sql_server/tutorial/create_a_login.cfm
    – Michael
    Jul 3, 2011 at 18:04
0

I have not done any development in PHP so I can't give advice about PHP side, but I've installed and configured SQL Server and have used it with .NET so I can surely suggest you what you might need to do to access database from another machine.

If you don't want to go crezy about security then I guess you should create just a simple database login by selecting "Mixed Mode Authentication" and then create "SQL Server Loging". Be sure to give that user enough privillages to perform CRUD operations on that database. Quick and dirty (but not best practice) is to enable SA account and use it everywhere !!

You will also need to check firewall settings. You need to make sure that firewalls are not blocking any connection between those two machines. If you have not changed by default SQL Server uses 1433 port for TCP and 1434 for UDP, so you might need to add exception in firewall rules for these ports.

If I were you and I would want to begin working on new project, I would use newer version of SQL Server which is SQL Server 2008 R2. And you can always restore older version backups (2000,2005,2008) to newer version of SQL Server (2008 R2).

0

Do you have SQL Server installed? If you've only installed the management studio, then you don't have a database server installed. You'll need to install an actual database server.

If you have a database server installed, then you can create a database, then tell the server to restore the database, and point at the .BAK file. That should pull the data out of the file and put it into a database so you can query it.

You must log in to answer this question.