Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Connection from php to sql server 2005 database using sqlsrv_connect()

authentication connection

  • Please log in to reply
15 replies to this topic

#1 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 05 October 2010 - 12:51 AM

Good day!

I’m here again posting about my problem in the connection of mssql to php.

I have a problem in my connection in mssql to php. I tried my best to fix my problem. Here is some data I could give for better understanding.

I used:

SQL Server 2005 Express
SQL Server Management Studio Express
IIS 6.0
php 5.2.4

I configure my php.ini
I uncommented the following:

cgi.force_redirect = 0
doc_root = “C:\Inetpub\wwwroot”
extension=php_mssql.dll
mssql.secure_connection = On

I change my ntwdlib.dll version from 2000.2.8.0 to 2000.80.194.0 because I found out that my older version of ntwdblib.dll was not work in sql server 2005 so I search for a ntwdblib.dll version that work on sql server 2005. So I deleted the old version and I put the new version of ntwdblib.dll in Windows/System32, php folder, and in php/ext folder.

And this is my information in my SQL Server:

Server Type: Database Engine
Server name: ISM\SQLEXPRESS
Authentication: Windows Authentication
Username: MR\Administrator ----This username was hiding
Password: ----Password was hiding


I have a big question in my mind and it is what username and password I could use in php to connect in mssql if the username and password is hiding. I try to use the sa and its password, but I don’t know if it is right. And also I try the MR\Administrator as username and the password is blank, but sad to say still I can’t connect.

Here is my code:



<?php
//mssql.secure_connection = On
// Need to upload ntwdblib.dll from net
$myServer = “ISM\SQLEXPRESS”; // host/instance_name
$myUser = “sa”; // username
$myPass = “xoxoxo″; // password
$myDB = “dbtest”; // database name
// connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die(“Couldn’t connect to SQL Server on $myServer”);
// select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die(“Couldn’t open database $myDB”);
echo “You are connected to the ” . $myDB . ” database on the ” . $myServer . “.”;
?>


After I run this code, the result is:

Fatal error:Call to undefined function mssql_connect() in C:\Inetpub\wwwroot\testconn.php on line 11

I don’t know what the problem is and what the configurations I need to do are.

I hope somebody can suggest or help me to fix my problem, because I really need to fix it.

Thank you in advance…

Edited by newphpcoder, 05 October 2010 - 04:42 PM.

  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 05 October 2010 - 02:40 AM

We cannot answer this, there is not even a question. Please restate what you wish to do (i.e. interface with an SQL database?) and not just give us code.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 08 October 2010 - 12:28 AM

Good day!

After connecting my php to sql server 2005 using the mssql_connect() syntax, which did not work. I try my best that I can to work it, but at the end I could not fix the error. So now, I try another option like I used Microsoft Driver for SQL Server and the syntax that I’m using is sqlsrv_connect()


Here are some configurations that I do to work the connection

1. I put the php folder in in C:\
2. I configure my IIS 6.0 to run php using isapi
3. I installed the SQLSRV20.EXE inC:\php\ext
4. I configure my php.ini
I uncommented the ff:
extension_dir = "./ext"
cgi.force_redirect = 0
doc_root = "C:\Inetpub\wwwroot"
I add extension=php_sqlsrv_53_ts_vc9.dll


I create a php file to test the connection

<?php
$server = "ISM\SQLEXPRESS";
$connectOptions = array("Database" => "dbtest");
//Because UID and PWD are not specified in the connection option
//The connection is made with Windows Authentication.
if($conn)
{
echo "Connection established";
}
else
{
echo "Connection could not be established";
}
?>


After I run this code I got an error like this:

Fatal error: Call to undefined function sqlsrv_connect() in C:\Inetpub\wwwroot\testconn.php on line 5

I don’t know where is the problem and how can I fix it.

I need to fix it as soon as possible, because almost 3 weeks I troubleshoot this connection.

Any help is highly appreciated
Thank you in advance.
  • 0

#4 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 08 October 2010 - 01:13 AM

You will need to enable extension=php_sqlsrv.dll in your PHP settings in php.ini, you then can verify it is enabled with phpinfo() after you had restarted your server.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#5 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 10 October 2010 - 04:48 PM

You will need to enable extension=php_sqlsrv.dll in your PHP settings in php.ini, you then can verify it is enabled with phpinfo() after you had restarted your server.


I already put the extension=php_sqldrv_53_ts_vc9.dll in my php.ini. How can I know if that extension was read in my phpinfo()?

And also I read that the sqlsrv is onyl work in php 5.3?i'M using php 5.2.4

Before I used the srlsrv i used mssql_connect() and it did not wokr so I try to used the sqlsrv now but still it did not work. I don't know what i the problem why it did not work.
  • 0

#6 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 10 October 2010 - 09:59 PM

You can view your loaded PHP extentions by placing this into a file and viewing it under your server:
<?php
phpinfo();
?>
To answer your question, Yes: You are loading a MSSQL driver for PHP 5.3, PHP will panic and not load this as there is a fundamental code base update in 5.3. You can either find a driver that will support your version or install a later working version of PHP from PHP: http://php.net/downloads.php#v5.3.0.
  • 0

#7 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 11 October 2010 - 12:58 AM

Good day!

I try a lot of configuration to work my connection from php to mssql but still I cannot connect. And I got a code to check if the mssql was loaded.

Here is the code:

<?php
if (function_exists('mssql_connect')){
echo "Okay, fn is there<br>------------------<br>";
} else {
echo "Hmmm .. fn is not even there<br>------------------<br>";
}

if(extension_loaded("mssql")) {
echo "MSSQL is Loaded<br>";
}
else {
echo "MSSQL not loaded<br>";
}

if(extension_loaded("msql")) {
echo "MSQL is Loaded<br>";
}
else {
echo "MSQL not loaded<br>";
}
echo '<br><br>';

$ext = get_loaded_extensions();
if(in_array('mssql', $ext))
echo 'u have mssql installed<br><br>';
else
echo 'u do NOT have mssql installed<br><br>';

phpinfo();
?>


And when I run this code the result is:

Hmmm….fn is not even there
----------------------
MSSQL not loaded
MSQL not loaded
You do NOT have mssql installed
And the list of phpinfo() appear.

Actually I run this code when my php version is php 5.2.4 and now I try it to php 5.1.4 and the result is still the same.

Web server is IIS 6.0
OS is Windows Server 2003 R2 Standard Edition
PHP version is php 5.1.4
MS SQL Server 2005 Express Edition –Windows Authentication.

I need to solved this problem because my connection in mssql is not working because call to undefined the function mssql_connect().

I hope somebody can help me. Almost three weeks I configure this connection and still I cannot connect.

Any help is highly appreciated.
Thank you.
  • 0

#8 CatchMeTux

CatchMeTux

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

Posted 11 October 2010 - 03:07 AM

:rolleyes:
  • 0

#9 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 11 October 2010 - 08:46 AM

have you activated the line "extension=php_mssql.dll" (by removing the semicolon at row start) in your php.ini and restarted your webserver? make sure it's the right php.ini you edit, some webservers has som wierd settings of own php.ini if I remember right
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#10 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 11 October 2010 - 04:57 PM

have you activated the line "extension=php_mssql.dll" (by removing the semicolon at row start) in your php.ini and restarted your webserver? make sure it's the right php.ini you edit, some webservers has som wierd settings of own php.ini if I remember right


Yes, I already activated extension=php_mssql.dll but removing the ; and I restarted my IIS server. But it's a big question in my mind and it is why in my phpinfo the Configuration File(php.ini) Path was in C:\WINDOWS, but it is in my C:\php and no php.ini in my WINDOWS.
And also when I configure my php.ini it has no take effect in my phpinfo()
  • 0

#11 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 11 October 2010 - 05:43 PM

You can view your loaded PHP extentions by placing this into a file and viewing it under your server:

<?php
phpinfo();
?>
To answer your question, Yes: You are loading a MSSQL driver for PHP 5.3, PHP will panic and not load this as there is a fundamental code base update in 5.3. You can either find a driver that will support your version or install a later working version of PHP from PHP: http://php.net/downloads.php#v5.3.0.


I try a lot of configuration to work my connection from php to mssql but still I cannot connect. And I got a code to check if the mssql was loaded.

Here is the code:

<?php
if (function_exists('mssql_connect')){
echo "Okay, fn is there<br>------------------<br>";
} else {
echo "Hmmm .. fn is not even there<br>------------------<br>";
}

if(extension_loaded("mssql")) {
echo "MSSQL is Loaded<br>";
}
else {
echo "MSSQL not loaded<br>";
}

if(extension_loaded("msql")) {
echo "MSQL is Loaded<br>";
}
else {
echo "MSQL not loaded<br>";
}
echo '<br><br>';

$ext = get_loaded_extensions();
if(in_array('mssql', $ext))
echo 'u have mssql installed<br><br>';
else
echo 'u do NOT have mssql installed<br><br>';

phpinfo();
?>


And when I run this code the result is:

Hmmm….fn is not even there
----------------------
MSSQL not loaded
MSQL not loaded
You do NOT have mssql installed
And the list of phpinfo() appear.

And now I noticed in my phpinfo() that all the changes in my php.ini did not take effect in my phpinfo(). And also in my phpinfo() the Configuration File (php.ini) Path is in C:\WINDOWS
  • 0

#12 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 11 October 2010 - 05:43 PM

You can view your loaded PHP extentions by placing this into a file and viewing it under your server:

<?php
phpinfo();
?>
To answer your question, Yes: You are loading a MSSQL driver for PHP 5.3, PHP will panic and not load this as there is a fundamental code base update in 5.3. You can either find a driver that will support your version or install a later working version of PHP from PHP: http://php.net/downloads.php#v5.3.0.


I try a lot of configuration to work my connection from php to mssql but still I cannot connect. And I got a code to check if the mssql was loaded.

Here is the code:

<?php
if (function_exists('mssql_connect')){
echo "Okay, fn is there<br>------------------<br>";
} else {
echo "Hmmm .. fn is not even there<br>------------------<br>";
}

if(extension_loaded("mssql")) {
echo "MSSQL is Loaded<br>";
}
else {
echo "MSSQL not loaded<br>";
}

if(extension_loaded("msql")) {
echo "MSQL is Loaded<br>";
}
else {
echo "MSQL not loaded<br>";
}
echo '<br><br>';

$ext = get_loaded_extensions();
if(in_array('mssql', $ext))
echo 'u have mssql installed<br><br>';
else
echo 'u do NOT have mssql installed<br><br>';

phpinfo();
?>


And when I run this code the result is:

Hmmm….fn is not even there
----------------------
MSSQL not loaded
MSQL not loaded
You do NOT have mssql installed
And the list of phpinfo() appear.

And now I noticed in my phpinfo() that all the changes in my php.ini did not take effect in my phpinfo(). And also in my phpinfo() the Configuration File (php.ini) Path is in C:\WINDOWS, but my php.ini is in my C:\php and also the extensio_dir in my phpinfo() is C:\php5 but in my php.ini extension_dir C:\php\ext
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download