Connecting Tech Pros Worldwide Forums | Help | Site Map

Mssql Iis6

Newbie
 
Join Date: Jul 2007
Posts: 11
#1: Jul 28 '07
Hi. I'm a newbie to PHP and am having a few problems as follows...

I have installed PHP successfully on server 1 which is running IIS 6 (W2k3) and hosting multiple sites, some of which connect to MSSQL 2k (SP4) on server 2 (using ASP).

I can load a basic 'Hellow world' PHP page hosted on server1 but when I add the code to create a simple connection to MSSQL on server 2, my PHP doesn't seem to connect nor output any of the desired query results to screen (e.g. number of rows in a table). I have placed 3 echo statements in amongst this page in order to see what is being processed successfuly as I have no other information as to where the failure may lie. Where can I find PHP error logs?

echo1, which appears at the start of the php script, writes to the screen fine.

echo2, which appears immediately after the MSSQL connection variable definition, does not write to the screen.

echo2, which appears after the MSSQL query results are to be written to the screen, does not write to the screen (nor do the query results).

The PHP script I am using is as follows:

<?php
echo '<p>line 1</p>';

$con = mssql_connect('MSSQLINSTANCE','username','password ') or die("Connection failed");

echo '<p>line 2</p>';

mssql_select_db('DATABASENAME', $con);
$sql = 'SELECT * FROM sys.tables';
if ($res = mssql_query($sql, $con)) {
print(mssql_num_rows($res) . " tables in database.\n");
} else {
print("SQL failed.\n");
}
mssql_close($con);

echo '<p>line 3</p>';

?>


Obviously, the values in CAPS above are replaced with the appropriate values for the MSSQL instance on server 2, administrator username, administrator password, and db name.

I have followed all the manuals, discussion boards and instructions I can find on the net and still no joy. I have named pipes and TCP/IP enabled on the MSSQL server. I have also addressed the issue of the ntwdblib.dll file version, by copying from the SQLserver across to the PHP directory and system32 directory on server1.

In addition to the problem above, and tracking back as far as I can, I am unable to get the file phpinfo.php to load on server1. I guess that I first of all need to solve this problem before tackling the MSSQL connection issue.

The phpinfo.php file reads a follows:

<?
phpinfo();
?>


All advice appreciated. Thanks in advance

volectricity's Avatar
Expert
 
Join Date: Jun 2007
Location: Baltimore
Posts: 587
#2: Jul 28 '07

re: Mssql Iis6


It sounds to me as though you have error_reporting turned off if your script fails at mssql_connect(), but doesn't tell you. You need to turn error_reporting on.

The problem is likely that the mssql extension is not loaded in your php.ini. Look in your php.ini and find this line:

extension=php_mssql.dll

Does it have a semicolon ahead of it? If so, remove the semicolon, save the file, and restart your server.
Newbie
 
Join Date: Jul 2007
Posts: 11
#3: Jul 28 '07

re: Mssql Iis6


ok. so now i'm making a little progress. i have turned on error reporting and now have the following error:

Parse error: syntax error, unexpected T_STRING in C:\filepath on line 10

my entire code is as follows:

<?php
echo "<p>line 1</p>";

error_reporting(E_ALL);
ini_set('display_errors', True);

$con = mssql_connect("MSSQLINSTANCE","administrator","pas sword") or die("Connection failed");
mssql_connect()

mssql_select_db("DBNAME");
$sql = "SELECT * FROM TABLENAME";
if ($res = mssql_query($sql, $con)) {
print(mssql_num_rows($res) . " tables in database.\n");
} else {
print("SQL failed.\n");
}
mssql_close($con);

echo "<p>line 2</p>";

?>


i removed one of the echo lines that i referred to earlier so there are now only 2, so that i can see when they are written, if at all. currently, using the exact code as above, neither of them are written, nor is anything other than the error message as shown above.

this error message appears to relate to the code that defines that DB name but i can't see what is wrong with this.

any ideas? (and apologies in advance for not grasping what i'm doing wrong!)
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#4: Jul 28 '07

re: Mssql Iis6


guswebb, kinldy use proper PHP code tags for your source code instead of bold. It will help others to understand your code.
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#5: Jul 28 '07

re: Mssql Iis6


On line 8, you have mssql_connect() without semicolon but still there is no need for 2nd mssql_connect(). Remove this line.
[PHP]<?php
echo "<p>line 1</p>";

error_reporting(E_ALL);
ini_set('display_errors', True);

$con = mssql_connect("MSSQLINSTANCE","administrator","pas sword") or die("Connection failed");
mssql_connect()

mssql_select_db("DBNAME");
$sql = "SELECT * FROM TABLENAME";
if ($res = mssql_query($sql, $con)) {
print(mssql_num_rows($res) . " tables in database.\n");
} else {
print("SQL failed.\n");
}
mssql_close($con);

echo "<p>line 2</p>";

?>[/PHP]
Newbie
 
Join Date: Jul 2007
Posts: 11
#6: Jul 28 '07

re: Mssql Iis6


Quote:

Originally Posted by mwasif

On line 8, you have mssql_connect() without semicolon but still there is no need for 2nd mssql_connect(). Remove this line.
[PHP]<?php
echo "<p>line 1</p>";

error_reporting(E_ALL);
ini_set('display_errors', True);

$con = mssql_connect("MSSQLINSTANCE","administrator","pas sword") or die("Connection failed");
mssql_connect()

mssql_select_db("DBNAME");
$sql = "SELECT * FROM TABLENAME";
if ($res = mssql_query($sql, $con)) {
print(mssql_num_rows($res) . " tables in database.\n");
} else {
print("SQL failed.\n");
}
mssql_close($con);

echo "<p>line 2</p>";

?>[/PHP]

i have removed the line 8 code and also checked the extension=php_mssql.dll entry in the php.ini file as per your PM. i changed this ini file before rebooting, but now it appeared again with a semicolon in front of the line where I had previously removed it. not sure how, maybe i didn't save it when i thought i had.

is the php.ini file only meant to be stored in the windows/system32 folder and not in the C:\PHP install folder?
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#7: Jul 28 '07

re: Mssql Iis6


You can know the location of php.ini in phpinfo output.
[PHP]<?
phpinfo();
?>[/PHP]
Newbie
 
Join Date: Jul 2007
Posts: 11
#8: Jul 28 '07

re: Mssql Iis6


and i still have the problem whereby my phpinfo.php file does not load anything other than a blank page, with no errors.

is there something more fundamental wrong with my installation/configuration that i need to get sorted before attempting to troubleshoot the MSSQL connection issue?

my phpinfo.php file reads...

[PHP]<? phpinfo() ?> [/PHP]

this renders a blank page, but from what i've read elsewhere, it should load a summary of my system's settings. is this correct?
Newbie
 
Join Date: Jul 2007
Posts: 11
#9: Jul 28 '07

re: Mssql Iis6


Quote:

Originally Posted by mwasif

You can know the location of php.ini in phpinfo output.
[PHP]<?
phpinfo();
?>[/PHP]


i have resaved the phpinfo.php file containing code exactly as you have typed it and still i get a blank page.
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#10: Jul 28 '07

re: Mssql Iis6


Quote:
from what i've read elsewhere, it should load a summary of my system's settings. is this correct?
It should load a summary.

Have you turned on error reporting? Try this code instead
[PHP]<?php
error_reporting(E_ALL);
phpinfo();
?>[/PHP]
Newbie
 
Join Date: Jul 2007
Posts: 11
#11: Jul 28 '07

re: Mssql Iis6


ok. now i'm getting somewhere. i can see the phpinfo output. this shows my php.ini file to be in the C:\Windows directory and not the system32 sub-directory. i have overwritten both versions with one that contains the extension=php_mssql.dll as loaded.

i am still getting the error in line 7 as above.
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#12: Jul 28 '07

re: Mssql Iis6


Did you set the correct value for extension_dir in php.ini? extension_dir will have the path where php_mssql.dll is located in your PHP directory.
Newbie
 
Join Date: Jul 2007
Posts: 11
#13: Jul 28 '07

re: Mssql Iis6


i did, but foolishly, and in my haste, i added this as an extra line of code near the top of the page, leaving the original line of code lower down. this meant that my custom value was being overwritten by the default.

so...i have corrected that problem and now have a more meaningful error relating to the MSSQL connection, as follows:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: MSSQLINSTANCE in C:\filepath on line 7
Connection failed


is it to do with the way in which the MSSQL instance is defined? i have seen threads that refer to this being in the format of

\\.\pipe\MSSQL$instance\sql\query
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#14: Jul 28 '07

re: Mssql Iis6


Did you read the user comments on http://www.php.net/manual/en/function.mssql-connect.php expecially this one?
Newbie
 
Join Date: Jul 2007
Posts: 11
#15: Jul 28 '07

re: Mssql Iis6


Quote:

Originally Posted by mwasif

Did you read the user comments on http://www.php.net/manual/en/function.mssql-connect.php expecially this one?

i did, but having gone back through them, and following the installation of MDAC 2.8, my connection now works!

i have had to use the notation of ,1433 to stipulate the port on the MSSQL server.

thanks for all your help.
Reply