Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to access ms sql server in php 1

Status
Not open for further replies.

jared5494

Technical User
Jun 9, 2002
111
US
Hello,
Ok, this file test.php was successful
<?php
echo "hey"
?>

so I know at least php works.

now the problem:
*********

i have a database setup in microsoft sql server named JAREDNET and the table in it named TEST with the following attributes: FIRSTNAME, LASTNAME, AGE. I populated the table with a few generic rows.

*********

I put the php_mssql.dll in the below directory and edited my php.ini and added the following lines:

extension_dir = "C:\Program Files\PHP\extensions"
extension=php_mssql.dll

*********

Now the code on my test_db.php
<?php
$server="localhost,1433";
$username="sa";
$password="";
$sqlconnect=mssql_connect($server, $username, $password);
$sqldb=mssql_select_db("JAREDNET",$sqlconnect);
$sqlquery="SELECT FIRSTNAME FROM TEST;";
$results= mssql_query($sqlquery);
while ($row=mssql_fetch_array($results)){
echo $row['FIRSTNAME']."<br>\n";}
mssql_close($sqlconnect);
?>

**********

when i try to access the php page, it just shows blank - no errors, no nothing. I am lost!

Thanks for any help or any insight!!

-Jared



 
a little more info i forgot to add:

I am running apache web server v 2.2.4
and PHP/5.2.1
and Microsoft SQL Server 2005 developer edition
Windows XP Pro
 
Your PHP code doesn't have enough error catching to make debugging your code easy. And I suspect that your PHP configuration isn't helping.

As a first step, maximize error-display in PHP. In php.ini, set:

[tt] display_errors = on
error_reporting = E_ALL[/tt]

I recommend this on all development systems.

As a second step, write your code so that it catches and reports errors. A more error-conscious version of your code might be:

Code:
<?php
$server="localhost,1433";
$username="sa";
$password="";
$sqlconnect=mssql_connect($server, $username, $password);
if ($sqlconnect !== FALSE)
{
	$sqldb=mssql_select_db("JAREDNET",$sqlconnect);
	
	if ($sqldb !== FALSE)
	{
		$sqlquery="SELECT FIRSTNAME FROM TEST;";
		$results= mssql_query($sqlquery);
		if ($results !== FALSE)
		{
			while ($row=mssql_fetch_array($results))
			{
				echo $row['FIRSTNAME']."<br>\n";
			}
		}
		else
		{
			print "error querying";
		}
	}
	else
	{
		print "error selecting DB";
	}

	mssql_close($sqlconnect);
}
else
{
	print "error connecting";
}
?>



Want the best answers? Ask the best questions! TANSTAAFL!
 
yea, even after i inserted that code, i am still drawing a blank screen. It has to be the php installation, so im going to redo it and ill get back to you. thanks for the advise though!
 
Did you restart your web server after making the changes to php.ini?

Are you certain you made the changes to the php.ini file PHP is reading?

What does the output of a script reading:

Code:
<?php
phpinfo();
?>

tell you about your php.ini file and your MSSQL connectivity?



Want the best answers? Ask the best questions! TANSTAAFL!
 
The output of a phpinfo script on my machine (a Linux box) has a section titled "mssql" that I do not see in yours.

I think PHP isn't finding your MSSQL DLL.



Want the best answers? Ask the best questions! TANSTAAFL!
 
No, I you can invoke PHP from the command-line. But if you intend to send script output to a web client, yes, you'll need a web server of some kind.



Want the best answers? Ask the best questions! TANSTAAFL!
 
ok, if you go to

i got the mssql section to show up, but still am not getting anything but a blank screen when i tried to submit a sql query through php (look for the code above)
 
ok i found out the answer,
for some reason localhost didnt work (even though everything is run on my computer) and when i switched my computer name with localhost, it worked.

odd, but thanks for all your help. defininetly helped for future troubleshooting!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top