Skip navigation links

MySQL Forums :: PHP :: Connecting PHP to SQL Express 2008 for first time


Advanced Search

Connecting PHP to SQL Express 2008 for first time
Posted by: dan eld ()
Date: February 14, 2012 11:18AM

Hi guys,

This is probably a problem with either a really easy solution, or I just missed something basic when I installed PHP or SQL.

Here's my setup: Windows Server 2008 R2 clean install a few weeks ago (this server will replace our current web server once we get it set up). I installed PHP 5.3.10 non-thread-safe to run through FastCGI. I installed SQL Express 2008, with the server as the default location (aka it is localhost instead of being named SQLEXPRESS).

I believe I've set up the handler mapping for PHP correctly, as scripts will run correctly.

SQL Express 2008 works just fine, as far as I can tell. When I load up SQL Server Management Studio, I am able to connect with the following settings:

Server Type: Database Engine
Server Name: (local)
Authentication: SQL Server Authentication OR Windows Authentication (either works)
Login: sa or my local windows acct
password: "sa" password or my windows password

So the problem for me is that I can't seem to get a connection using PHP on the server. Checking other sites for help, they recommended just getting a basic PHP script that tries to connect to the server and spits out an error if it can't.

Can anyone give me some pointers why this script:

<?php
$host = "(local)";
$user = "sa";
$passw = "(mySApassword)";
$db = "SqlTest";
if (!$link = mysql_connect($host, $user, $passw)) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db($db, $link)) {
echo 'Could not select database';
exit;
}

print("ok!");
?>

Would give me the "Could not connect to mysql" error?

Note: I've tried a few troubleshooting things already, including all sorts of combos of different hosts (localhost, 127.0.0.1, the server's actual IP, the windows name of the web server). Also I've tried different combos of windows username/passwords when changing the host name up too.

Also, I've tried this all with and without the windows firewall active.

Is there something simple I'm missing? I'm thinking for some reason PHP isn't allowed to communicate with the SQL database... Did I forget to set some basic permissions somewhere? I'm at a loss here. Just trying to get a shopping cart set up that uses PHP and SQL. In my head, it didn't seem this complicated.

Options: ReplyQuote


Subject Written By Posted
Connecting PHP to SQL Express 2008 for first time dan eld 02/14/2012 11:18AM
Re: Connecting PHP to SQL Express 2008 for first time Barry Galbraith 02/14/2012 09:28AM
Re: Connecting PHP to SQL Express 2008 for first time dan eld 02/15/2012 09:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.