connecting to MS SQL from ubuntu PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
consoleart
Forum Newbie
Posts: 2
Joined: Tue Feb 17, 2009 7:07 am

connecting to MS SQL from ubuntu PHP

Post by consoleart »

Hi all, being a windows developer for so long, i have moved to PHP in linux environment.

Have installed the necessary development environment for PHP....now iam trying to connect to my windows - MS SQL server 2005,

i am getting an error Cannot connect to server <servernme>, the username and password are correct and iam able to access the windows machine from my networks...please tell me how to resolve this...thnx in advance...

sorry if iam posting the question at a wrong place, i thought posting here might shed some light on ...thnx again
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: connecting to MS SQL from ubuntu PHP

Post by panic! »

Please post your code so we can assist you further
consoleart
Forum Newbie
Posts: 2
Joined: Tue Feb 17, 2009 7:07 am

Re: connecting to MS SQL from ubuntu PHP

Post by consoleart »

here is the code that i use
#!/usr/bin/python
import _mssql
//the error comes in the next line
mssql=_mssql.connect('jagserver','sa','mypassword')

mssql.select_db('dbnamehere')

query="select [maintenance name],[maintenance code] from [maintenance routines];"
if mssql.query(query):
rows=mssql.fetch_array()
rowNumbers = rows[0][1]
print "Number of rows fetched: " + str(rowNumbers)
for row in rows:
for i in range(rowNumbers):
print str(i) + "\t" + row[2][0] + "\t" + row[2][1] + "\t" + str(row[2][2])
else:
print mssql.errmsg()
print mssql.stdmsg()
mssql.close()

and i have installed python-pymssql
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: connecting to MS SQL from ubuntu PHP

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: connecting to MS SQL from ubuntu PHP

Post by Benjamin »

Is your server accepting remote connections? Is there a firewall blocking that port?
Post Reply