python - Echo pyodbc output in php script in Ubuntu 14.04 -


i have ubuntu 14.04 machine running local server.

on server, have php script needs access data on remote microsoft azure sql database.

i unable find way access database ubuntu uing purely php, tried out python script , imported pyodbc library after following tutorial: https://snakeycode.wordpress.com/2013/12/04/installing-pyodbc-on-ubuntu-12-04-64-bit/

i can run script fromthe terminal, , connects azure sql database , prints output of query console.

this great news, began test out on local server.


on server, in php method, call echo shell_exec('my_script.py');

this gives me error:

pyodbc.error: ('08001', '[08001] [unixodbc][freetds][sql server] unable connect data source (0) (sqldriverconnect)') 

why my_script.py not work when executed local server?

use tds version 8.0 , mention same in pyodbc.connect connection string.

sample code:

#!/usr/bin/python "proof connection @ pyodbc level." # test pyodbc connection.  import pyodbc  conn = pyodbc.connect('driver=freetds;dsn=mssql;uid=userid@servername.database.windows.net;pwd=xxxxxxxx;tds_version=8.0;') cursor = conn.cursor() cursor.execute("select * sys.tables") print( cursor.fetchall() ) conn.close() 

content of : /etc/freetds/freetds.conf:

[global]         # tds protocol version         tds version = 8.0          # whether write tdsdump file diagnostic purposes         # (setting /tmp insecure on multi-user system)         dump file = /tmp/freetds.log         debug flags = 0xffff          # command , connection timeouts ;       timeout = 10 ;       connect timeout = 10          # if out-of-memory errors, may mean client         # trying allocate huge buffer text field.         # try setting 'text size' more reasonable limit         text size = 64512  # typical sybase server #[egserver50] #       host = symachine.domain.com #       port = 5000 #       tds version = 5.0  # typical microsoft server [mssql]         host = servername.database.windows.net         port = 1433         tds version = 8.0 

content of /etc/odbc.ini file:

[mssql] driver = freetds description = odbc connection via freetds trace = yes servername = mssql database = databasename tds_version = 8.0 

contents of /etc/odbcinst.ini file:

[freetds] description=freetds driver driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so setup=/usr/lib/x86_64-linux-gnu/odbc/libtdss.so 

please let know if still cannot access , provide exact error run into.

also important step add ip address running code firewall rules on sql azure database.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -