Connecting Tech Pros Worldwide Forums | Help | Site Map

mssql connectino error

Member
 
Join Date: Aug 2006
Posts: 110
#1: Apr 26 '07
Dear Friends,

I am trying to connect php with mssql server but I am getting into an error "

Fatal error: Call to undefined function: mssql_connect() in /home/afcind/public_html/test.php on line 9

Here is the php code :

[PHP]<?php
//Connect To Database
$db_host="202.71.136.236";
$db_user="afcind";
$db_pwd="afcindia123";
$dbname="afcind";
$table="userlogin";

mssql_connect($db_host, $db_user, $db_pwd) or die ("coudn't connect to database");

if (mssql_select_db($dbname)){

echo "Database selected";
}
else{
die("Can't select database");
}

?>[/PHP]

Please help me.........

Thanks
Deepak

Newbie
 
Join Date: Apr 2007
Posts: 3
#2: Apr 26 '07

re: mssql connectino error


Quote:

Originally Posted by deepaks85

Dear Friends,

I am trying to connect php with mssql server but I am getting into an error "

Fatal error: Call to undefined function: mssql_connect() in /home/afcind/public_html/test.php on line 9

Here is the php code :

[PHP]<?php
//Connect To Database
$db_host="202.71.136.236";
$db_user="afcind";
$db_pwd="afcindia123";
$dbname="afcind";
$table="userlogin";

mssql_connect($db_host, $db_user, $db_pwd) or die ("coudn't connect to database");

if (mssql_select_db($dbname)){

echo "Database selected";
}
else{
die("Can't select database");
}

?>[/PHP]

Please help me.........

Thanks
Deepak

try this way

[PHP]
<?
$dbhost="202.71.136.236";
$dbuser="afcind";
$dbpass="afcindia123";
$dbname="afcind";


$dc = mssql_connect($dbhost,$dbuser,$dbpass);
mssql_select_db($dbname,$dc) or die("Couldn't connect to SQL Server");
// Connect now.

?>
[/PHP]

Best regards,
Mainul
Member
 
Join Date: Aug 2006
Posts: 110
#3: Apr 26 '07

re: mssql connectino error


Thanks for your suggestion mainul.........but I am still getting the same error.

Please help me..........


Quote:

Originally Posted by mainul05

try this way

[PHP]
<?
$dbhost="202.71.136.236";
$dbuser="afcind";
$dbpass="afcindia123";
$dbname="afcind";


$dc = mssql_connect($dbhost,$dbuser,$dbpass);
mssql_select_db($dbname,$dc) or die("Couldn't connect to SQL Server");
// Connect now.

?>
[/PHP]

Best regards,
Mainul

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#4: Apr 27 '07

re: mssql connectino error


This is very odd. The error message
Expand|Select|Wrap|Line Numbers
  1. Call to undefined function: mssql_connect
seems to indicate that PHP cannot find the mssql function. Although if the wrong type or number of parameters are passed a similar error is possible(Or is that C#?). Try writing a simple test script with different mssql functions without mssql_connect(). PHP will try to establish a connection anyway. Try [PHP]function_exists (mysql_function_name )[/PHP] and [PHP]get_defined_functions (mysql_function_name ). [/PHP] Then tell us the errors or messages
Member
 
Join Date: Aug 2006
Posts: 110
#5: May 7 '07

re: mssql connectino error


Quote:

Originally Posted by code green

This is very odd. The error message

Expand|Select|Wrap|Line Numbers
  1. Call to undefined function: mssql_connect
seems to indicate that PHP cannot find the mssql function. Although if the wrong type or number of parameters are passed a similar error is possible(Or is that C#?). Try writing a simple test script with different mssql functions without mssql_connect(). PHP will try to establish a connection anyway. Try [PHP]function_exists (mysql_function_name )[/PHP] and [PHP]get_defined_functions (mysql_function_name ). [/PHP] Then tell us the errors or messages



Yes you were write. I have tried to test a script.

[PHP]if (function_exists('mssql_fetch_row')) {
echo "MSSQL functions are available.<br />\n";
} else {
echo "MSSQL functions are not available.<br />\n";
}[/PHP]

and it showed me "MSSQL functions are not available.

Now please tell me what should I do.

Thanks
Deepak
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#6: May 8 '07

re: mssql connectino error


To be honest I don't know. I can only think of two reasons why the functions are unavailable.
1. They didn't come with the PHP package that you installed.
2. They are disabled either within a config file or commented out within the code.
If you don't feel confident enough to search through the files looking for the missing functions I can only suggest downloading a newer/better PHP package.
I have never had any such problems with XAMMP
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#7: May 9 '07

re: mssql connectino error


You will need to install and configure the MSSQL to work with PHP. PHP.net is a great resource for this information.

Quote:

Originally Posted by code green

To be honest I don't know. I can only think of two reasons why the functions are unavailable.
1. They didn't come with the PHP package that you installed.
2. They are disabled either within a config file or commented out within the code.
If you don't feel confident enough to search through the files looking for the missing functions I can only suggest downloading a newer/better PHP package.
I have never had any such problems with XAMMP

Newbie
 
Join Date: May 2007
Posts: 2
#8: May 9 '07

re: mssql connectino error


please try this
I connected a WinXp prof ver 2002 sp2 box to a MsSQL server 2005.

Here is how (Assuming the MsSQL server is already running).

I installed the IIS via WinXP cd.
I downloaded and ran the file:

php-5.2.1-win32-installer.msi

(I chose IIS + ISAPI in the installation process)

I downloaded the files:
ntwdblib.dll (as mentioned in various posts above)
and
php_mssql.dll (found it in other PHP distributions)

I copied those files into the root PHP directory and modified the PHP.ini adding: extension=php_mssql.php.
(note: The downloaded file php_mssql.dll may have to be put in the php\ext folder instead of the root php folder depending on your extension path)

Reboot the IIS.

The php code for the connection is:

$this->sql_link = '0';
function connection() {
$this->sql_link = mssql_connect($this->"MyHost-NotIP", this->"MySelf", $this->"SomePass");
mssql_select_db($this->"Databasename", $this->sql_link);
}

Regards
Ajay kumar
Reply