Hi everyone!
I have PHP page to display some statistics relating to my companies product performance in the marketplace. The powers that be have now decided that they want a second page that shows graphs to illustrate trends. One of the other guys in the office created an app that collects the data and then writes it to an SQL database.
So I'm thinking PHP connecting to a database, I've done that several times before with a MySQL DB and that was a piece of cake. Then I tried it. OMG! When ever I try to run a script that connects to the database it executes everything up to the database connection and then nothing. the page is displayed and anything below the connection simply doesn't get sent over. Based on that I'm guessing that there are several things I need to do before but i haven't a clue what those things are. With a deadline looming and a dead end found assistance would be greatly greatly appreciated!
cheers,
ben
PS The app, its database and the PHP pages are all on the same server. Also I'm viewing the database is in SQL Server 2005.
Connect PHP to an SQL database
Moderator: General Moderators
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Connect PHP to an SQL database
Show us some code and errors that you get.
Re: Connect PHP to an SQL database
Cool...
I'm not sure how to get a propper error message back from the attempted connection when dealing with MS SQL so the error message is a rather unhelpful...
"Can\'t connect to server"
Cheers for any help you can give.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>Start</p>
<?php
$servername='localhost\SQLEXPRESS,4498';
$username='sqltest';
$password='sqltest';
$connection = mssql_connect($servername,$username, $password) or die ($failed = 'Can\'t connect to server');
mssql_select_db('tempdb', $connection);
mssql_close ($connection);
echo $failed;
?>
<p>End</p>
</body>
</html>"Can\'t connect to server"
Cheers for any help you can give.
Re: Connect PHP to an SQL database
Eureka!
So I made a change to the server name so it now reads xx.xx.xx.xx,4498 (xx replaces the obviously not to be shared IP address). This seems odd because the PHP stuff is run on the same machine as the DB so I would have thought local host would have worked just as well (go figure huh?). I also deleted the ntwdblib.dll (ver 2000.2.8.0) in c:\php and placed ntwdblib.dll (ver 2000.80.194.0) [[found here http://www.nodevice.com/dll/N/page12.html]] into c:\windows\system32. Enabled TCP/IP in the SQL Server Configuration Manager >> Protocols for SQLEXPRESS.
AND IT WORKS!
Now to actually do something with my newly found connectivity.
Thanks for the reply anyway EverLearning. I'm sure something new will go wrong soon enough for you to flex your brain muscles and save me.
cheers,
ben
So I made a change to the server name so it now reads xx.xx.xx.xx,4498 (xx replaces the obviously not to be shared IP address). This seems odd because the PHP stuff is run on the same machine as the DB so I would have thought local host would have worked just as well (go figure huh?). I also deleted the ntwdblib.dll (ver 2000.2.8.0) in c:\php and placed ntwdblib.dll (ver 2000.80.194.0) [[found here http://www.nodevice.com/dll/N/page12.html]] into c:\windows\system32. Enabled TCP/IP in the SQL Server Configuration Manager >> Protocols for SQLEXPRESS.
AND IT WORKS!
Now to actually do something with my newly found connectivity.
Thanks for the reply anyway EverLearning. I'm sure something new will go wrong soon enough for you to flex your brain muscles and save me.
cheers,
ben