1.11M Members

Using PHP to connect to remote MSSQL database

 
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.

 
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

 
0
 

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

 
0
 

Thanks for the information!

 
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

 
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

 
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

 
0
 

hi

sorry i don't know

i cann't help u

sorry

 
0
 

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

 
0
 

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

An english teacher, for a start.:-|

 
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 8 Years Ago by papa_fal, manish812, demo and 2 others
 
0
 

An english teacher, for a start.:-|

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

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

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