By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

mssql connectino error

100+
P: 114
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
Apr 26 '07 #1
Share this Question
Share on Google+
7 Replies


P: 3
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
Apr 26 '07 #2

100+
P: 114
Thanks for your suggestion mainul.........but I am still getting the same error.

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


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
Apr 26 '07 #3

code green
Expert 100+
P: 1,726
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
Apr 27 '07 #4

100+
P: 114
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
May 7 '07 #5

code green
Expert 100+
P: 1,726
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
May 8 '07 #6

Motoma
Expert 2.5K+
P: 3,235
You will need to install and configure the MSSQL to work with PHP. PHP.net is a great resource for this information.

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
May 9 '07 #7

P: 1
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
May 9 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.