1,105,320 Community Members

Using PHP to connect to remote MSSQL database

Member Avatar
Puckdropper
Posting Pro in Training
494 posts since Jul 2004
Reputation Points: 7 [?]
Q&As Helped to Solve: 24 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello,

I installed PHP 5 on my Server 2003 machine with IIS and got that working properly. I want to connect to my school's MS-SQL student database, but PHP balks when it hits "mssql_connect" (or whatever the statement is). How can I set this up so I can actually connect to the database?

Apparently I need a file that's included with SQL Server (which I don't have) in order to get PHP to do this. Is there a way to get this file (nwtdb--something) so I can connect the database?

The whole motivation with this is being able to write and test the PHP code for the database without having to find times one of the labs on campus is open... they won't give users FTP access so you can't upload your files and test them from the web interface on their machine.

Member Avatar
demo
Newbie Poster
18 posts since Jan 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi

You first need the information that your school has given you to access the database...

This will include...

Database User Name
Database Password
Database Server Name
Database Server Port (#) it is listening on
Database Name you have permission to access
Database tables you have permissions to access

One you have this then you can connect using the following PHP functions

// connect
$cs = mssql_connect ( 'server_name:port', 'username', 'password' ) or die ( 'Can not connect to server' );

// select
mssql_select_db ( '[database_name]', $cs ) or die ( 'Can not select database' );

//query
$sql = "SELECT * FROM [TABLENAME]";
$r = mssql_query ( $sql, $cs ) or die ( 'Query Error' );

// loop the result

while ( $row = mssql_fetch_array ( $r ) )
{
	/* do stuff */
}

demo

Member Avatar
DanceInstructor
Posting Whiz
355 posts since Feb 2005
Reputation Points: 19 [?]
Q&As Helped to Solve: 15 [?]
Skill Endorsements: 0 [?]
 
0
 

From everything I have read you have to have a copy of the MS-SQL server to get that file...

Member Avatar
Puckdropper
Posting Pro in Training
494 posts since Jul 2004
Reputation Points: 7 [?]
Q&As Helped to Solve: 24 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for the information!

Member Avatar
papa_fal
Newbie Poster
4 posts since Jun 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hello to all
i want connect to mssql insist of mysql ,i want design a web site with ,as default this CMS work with mysql,and how i can change setting that php read table of (sql server) insist of mysql.??? plz explain with details[i am in low level] i am wait for your responses. i hope that put this question in suitable place. thanks[php nuke],as default this CMS work with mysql,and how i can change setting that php read table of (sql server) insist of mysql.???
plz explain with details
i am wait for your responses.

i hope that put this question in suitable place.

thanks

Member Avatar
manish812
Newbie Poster
12 posts since Jun 2006
Reputation Points: 11 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hey wht u r using to connect with mysql
i also use php in window with IIS server and using mysql but i connect it very easy.
mysql_connect("host_name","user","password")
simple hai agar koi problem ho thn mail me -----manish812@gmail.com

Member Avatar
papa_fal
Newbie Poster
4 posts since Jun 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hello
thanks alot of your attention.
yes,i know that mysql is better ,but my boss wants change (mysql db) to (sql server db) for (nuke[that is a CMS]).
you know that (nuke)works as default with (mysql).and i want change [connections] is special files .but i donot know where are they????and how??
do you work with nuke????and do you can help me??
i am very confused.
thanks of you .
i am wait for your response.
[plz wirte to me only to english]
with best regards.
good bye

Member Avatar
manish812
Newbie Poster
12 posts since Jun 2006
Reputation Points: 11 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hi

sorry i don't know

i cann't help u

sorry

Member Avatar
papa_fal
Newbie Poster
4 posts since Jun 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hi
ok thanks,never mind.
is person that can help me??

Member Avatar
JNathanson
Newbie Poster
9 posts since May 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hi
ok thanks,never mind.
is person that can help me??

An english teacher, for a start.:-|

Member Avatar
Puckdropper
Posting Pro in Training
494 posts since Jul 2004
Reputation Points: 7 [?]
Q&As Helped to Solve: 24 [?]
Skill Endorsements: 0 [?]
 
0
 

I forgot about this post, but did find the answer I was seeking.

Apparently, I did not have php.ini properly configured so PHP could find it. Therefore, it wouldn't recognize my config and the option to use the mssql database.

To fix this, I uncommented the ;extension=php_mssql.dll line in php.ini and everything was happy.

Question Answered as of 7 Years Ago by papa_fal, manish812, JNathanson and 2 others
Member Avatar
papa_fal
Newbie Poster
4 posts since Jun 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

An english teacher, for a start.:-|

i am sorry for some persons.
ya you can be my english teacher.
:lol:

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article