Ubuntu 12.04 LTS Precise
I'm trying to use PHP to connect to a remote Windows Sybase database. Let us assume Windows 7 Enterprise SP1. I'm currently doing this in PHP:
$db = sybase_connect("10.1.208.111", "$user", "$pass");
And I'm getting an error of:
Warning: sybase_connect(): Unable to connect to server: 10.1.208.111
I understand that the server I'm connecting to (10.1.208.111), needs to be in the interfaces file. I'm trying to figure out where that is, or even if I have one on the Ubuntu server (I'm still new to linux itself). I read that the path for the file is located in the SYBASE environmental variable. I don't know where that is either. Can anyone shed some light? I can offer more information if you need it, I just don't know what you need right off the bat.
PS: The windows machine has Micros RES installed on it. That's the database I'm trying to pull data from. Not sure if that matters.
The default installation directory for Sybase ASE in windows is C:\sybase, so your interfaces (interfaces.ini) should be located there.
For SQL Anywhere, the interfaces file is called SQL.ini, and it's location varies, but you should be able to do a search of your system drive to find it.
For SQL Anywhere you probably want to use the PHP apis that are provide by SAP Sybase. The SQL Anywhere documentation is a pretty good place to start, as it covers all the pieces that need to be installed to get SQL Anywhere to talk to PHP.
SQL Anywhere 11: SQL Anwhere PHP API
You may also be able to find good information over at the SAP Community Network site for SQL Anywhere.
Related
EDIT:
It is entirely possible to do this for free This still requires a license, I'm not sure how much or exactly which license is needed as mine was bundled with my installer.
I'm trying to connect to an IBM i DB2 server from a local PC as part of a PHP application. I'm trying to set myself up for local development.
I can't find a download for "IBM DB2 Universal Database client" and/or "IBM DB2 Connect" mentioned below. Has anyone done this before and could lend some insight? I'm open to alternate solutions so long as the db2_* functions are available. I'm working with existing code with no easy/quick way to switch between connection types between development and production.
This is a near duplicate question as here but that too did not have an answer. The OP ended up giving up and connected with "IBM Client Access OLE DB" using "IBMDA400", but I also can't find a download for it. I'm not even sure if this method would enable the db2_* functions either.
I'm using a Bitnami Wamp stack (https://bitnami.com/stack/wamp)
I have downloaded the php_ibm_db2.dll from
https://pecl.php.net/package/ibm_db2 and added
extension=php_ibm_db2.dll to my php.ini file.
I've confirmed the php.ini file is the one being used by checking the
output of echo phpinfo(); and successfully modifying it.
I've also placed php_ibm_db2.dll in the location specified by the
extension_dir directive. extension_dir = "C:\Bitnami\wampstack-5.6.29-1\php\ext"
The only PHP error I see logged is when I start up the server (which is still successful - albeit no db2_* functions).
[18-Jan-2017 21:08:18 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Bitnami\wampstack-5.6.29-1\php\ext\php_ibm_db2.dll' - The specified module could not be found.
in Unknown on line 0
[18-Jan-2017 21:08:19 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Bitnami\wampstack-5.6.29-1\php\ext\php_ibm_db2.dll' - The specified module could not be found.
in Unknown on line 0
But the file C:\Bitnami\wampstack-5.6.29-1\php\ext\php_ibm_db2.dll does exist and has the same exact permissions as every other *.dll file in the directory (which has not been modified since the Wamp stack was installed).
I have read that "IBM DB2 Universal Database client" and "IBM DB2 Connect" must be installed on the same machine running PHP here but am having trouble finding a download for either. I can find instructions on how to install each, but no download link.
I've found a download for "IBM Data Server Client" which is behind a log in on IBM's site. I'm wondering if this is one of the two programs I need installed just by a different name. I know name consistency isn't IBM's best attribute... :D
I have some answers.
JDBC and ODBC support is free and it is typically shipped with other IBM software. This doesn't help in regards to db2_* functions in PHP.
If your DB2 database is on an IBM i or even Z/OS then the only way to do this is with DB2 Connect. There are a few different versions, but for workstation development you would want DB2 Connect Enterprise Edition. The downside is the smallest number of packages they currently offer is 25 users at ~$3,800. This comes out to about $152/user but for a small shop with only 2 or 3 developers this is effectively out of the question unfortunately. At one point they did offer a 5 license package, but as of now they no longer offer it. Hopefully they will in the future.
If your DB2 database is on LUW then all you need is IBM Data Server Client which can be downloaded for free from here (requires IBM account though):
https://www-01.ibm.com/marketing/iwm/iwm/web/reg/pick.do?source=swg-idsc97&lang=en_US
A potential alternative is to serve an API from the IBM i which is consumed by a local workstation during development of an application other than the API. However development of the API itself would still only be able to be done on the system AFAIK. You could also setup a local DB2 database as well and copy any files over. There would be further differences between production and development, but could save some money.
Personally I think it is absurd they charge for the ability to remotely connect to the DB2 database on IBM i or Z/OS using a method other than JDBC or ODBC but charge nothing for LUW. Coupled with the fact that the smallest package is for 25 users makes it even more discouraging for small to mid-sized business (the primary customers for IBM i).
I got this working with just "IBM Data Server Client". First I installed a Wamp stack from Bitnami, PHP 5.6.30 32bit. Then I downloaded IBM Data Server Client from the passport advantage area. I haven't tried the version from here after getting it working though, so that one might work as well. These steps are based on the version I got from passport advantage. It has an install wizard, so you can just follow the steps, but here is an IBM article on the process. That article includes installation directions for other software in addition to IBM Data Server Client, so only pay attention to the ones which apply. After installation you have to configure the client from a Window's Command prompt. To do so I followed this article. To summarize, you have to catalog the node (server) and then catalog the database. Then you restart the session and test it by connecting. Syntax is below:
<+NODENAME+> is made up by you. <+REMOTE+> is the FQDN or IP. <+PORT+> is the port of the <+REMOTE+> you should be connecting with. Usually the port will be 446. <+database_name+> is the database name.
db2 catalog tcpip node <NODENAME> remote <REMOTE> server <PORT>
db2 catalog database <database_name> at node <NODENAME>
Db2 terminate
db2 connect to <database_name> user <user_name> (you will then be prompted for a password)
Once this is complete you have to get the Windows PHP ddl for the IBM_DB2 driver from here. I used version 1.9.9. Then move the php_ibm_db2.dll file to your PHP extension directory as specified in the extension_dir directive in your php.ini. Then add this line to you're php.ini extension=php_ibm_db2.dll. Then restart Apache and you should be able to connect. While successfully connecting to the DB, I'm still having issues with unqualified tables at this point. It seems to use the username instead of the provided library list despite the library list being set correctly. I'll update when I figure this part out.
This is a rough outline of what I had to do to get it working in my particular situation and not intended to be an all encompassing tutorial. If your environment is different you may have to adjust. Additionally I'm not sure if there are any other dependencies for php_ibm_db2.dll which happened to already be satisfied for me. Hopefully this will at least save someone some time and money.
I solved the library list issue; See this answer: https://stackoverflow.com/a/43193058/967617
I'm trying to connect with Laravel 4 to an SQL Server database. I'm getting an error, but I think it's a PHP error, not a Laravel error. It says PDOException: could not find driver. I have the driver set to sqlsrv like another example in the database.php file. Like I said, I think this is a PHP error, not Laravel.
I'm on localhost on my Mac. Do I need to configure something in my php.ini file? I found another article that said I need to comment out a MySQL driver under PDO. I also couldn't find that line in my php.ini. But I need to connect to a MySQL database as well, anyway. What do I need to change in my php.ini file?
I found this line:
pdo_mysql.cache_size = 2000
But commenting it out did nothing even after restarting Apache.
The sqlsrv driver is a windows-only driver according to the PHP Manual (www.php.net/manual/en/sqlsrv.requirements.php). So you can't use that driver on Mac, Linux, Unix or any other operating system than the ones listed on that page.
I assume you are trying to connect to a remote SQL Server somewhere? If you're on Mac, then SQL Server wouldn't be running on your local machine, so I guess the first question is whether or not you have a SQL Server running somewhere.
Second, from the server that is running PHP, you would need to connect using either FreeTDS or ODBC with FreeTDS.
Since Laravel 4 uses PDO, you'll need to install FreeTDS and ODBC. Laravel 4 doesn't use the mssql PHP extension. It uses PDO, so mssql won't get you anywhere with Laravel 4.
If you're serving PHP from your Mac, I would say there are generally 4 different ways you could go:
The Easy, but costly way: Go to (www.macupdate.com/app/mac/23152/openlink-odbc-driver-for-sybase) and download and install OpenLink ODBC driver. This allows you to create new ODBC connections using the Sybase (MSSQL) driver on a XNIX machine. There's an installation walk-through here (wikis.openlinksw.com/dataspace/owiki/wiki/UdaWikiWeb/InstallSybaseExpressOSX). It comes with a 15 day trial, after which you would have to purchase it. As of this writing, it appears to cost somewhere in the range of $30 - $50 depending on the license you choose.
The harder, but free way: Follow http://blog.benjaminwalters.net/?p=10 (slightly outdated) to re-compile FreeTDS support into PHP on Mac (assuming you're using MAMP)
The far better, but also far more work way: Find a Virtual Machine Host software like VMWare Fusion and install a Linux server like Ubuntu 12.4. Make sure you install apache2 and PHP during the install process and then follow the steps here to get FreeTDS working on your new server machine.
Run PHP from the Windows Server that is running SQL Server
Milage will vary with each solution, and there is a learning curve in any case. I've been a PHP developer for a long time, and it took me days to figure out how to get connected to SQL Server for the first time from Linux. Thankfully, there are quite a few walkthroughs out there now, and FreeTDS has come a long way since that time.
Hope that helps. :)
I actually have this running on my setup. My best advice is to get on the Homebrew bus.
https://github.com/josegonzalez/homebrew-php is where you're going to want to look for installing PHP and related items. I don't remember exactly what I did but it wasn't particularly difficult.
First you'll need FreeTDS.
brew install freetds
Then, add Jose's formulas to your homebrew (instructions on the github page). After that,
brew install php5x --with-mssql
brew options php5x
if you need more extensions.
Based on Jon Watson's comment,
I've tried step 2, and it doesn't work. check my issue here https://github.com/laravel/laravel/issues/2180
Step 3 is broken link and I think it's the same with step 2.
I also tried linux ODBC driver for Laravel (there are 2, google it), both doesn't work too. Although my simple test php works in both DBLIB and ODBC (compiled using official microsoft odbc unix driver).
Step 4 definitely works, BUT you must use IIS for best stability.
That leaves step 1. OR,
Ditch Laravel4 and use good ol' AdoDB http://adodb.sourceforge.net/ which I've been using since 2006 and still working superbly (although not modern like Laravel) configure it using tutorial in http://docs.moodle.org/20/en/Installing_MSSQL_for_PHP
I wonder why they don't build sqlsrv driver for linux too....
Im trying to run a shell with cakephp but I'm not able to do it due to a SQL connection error, I'm always getting this
Warning:mssql_connect(): Unable to connect to server: XXXXX I'm sure the config for the data source is correct as I'm able to connect using the website side of the app.
Have anyone stumble with something like this?
BTW the webserver and the mssql server are not the same, they are on different hosts.
Environment Info ( I agree is a mess... ):
Web server
Windows server 2003 R2
PHP-5.2.4
IBM http server 6.1
Cakephp 1.2
DB Server
Windows server 2003 R2
Microsoft SQL server 2005
I have isolated the problem and found is not cakephp related, I created a script with just this line of code
mssql_connect('XXXX', 'YYYY', 'ZZZZ', true);
Giving me the same error. This should be something different between CLI and how php is run from the HTTP server.
Thank you!
Make sure you specify the port to connect to (usually 1433). If that still doesn't work its possible you need to play with named pipes settings. More information can be found in the comments on the PHP site: http://ca3.php.net/function.mssql-connect
I would also suggest you look into using the Microsoft SQL Serv drivers for PHP, they are much better maintained than the mssql ones. http://www.microsoft.com/download/en/details.aspx?id=20098 Here is an article explaining the differences: http://blogs.msdn.com/b/brian_swan/archive/2010/03/08/mssql-vs-sqlsrv-what-s-the-difference-part-1.aspx If you do go the sqlsrv route (and I really suggest you do) here are the connection parameters: http://php.net/manual/en/function.sqlsrv-connect.php Use example 3.
Here are the steps I followed to narrow and then fix the problem:
Check which php.ini is your cli using by running the next command: php -i
Isolate the problem, I was thinking it was something with cakephp, but at the end every problem is related to a single line in php, my problem was around this line of code mssql_connect('XXXX', 'YYYY', 'ZZZZ', true);
Based on the info provided here I found out that the next dll was outdated or not compatible with Windows Server 2003, just get ntwdblib.dll ver. 2000.80.2039.0, use this exact version as others like ver.2000.80.194.0 didn't worked for me.
As #charles mentioned if you are not working already in a project already deployed use sqlsrv drivers as those are maintained currently and the mssql are basically getting deprecated.
Thanks!
I'm currently working on a project that has to write to both MSSQL and a Sybase database.
I'm working on a Microsoft Server 2008 R2 server with IIS 7 and PHP installed (cause I've got to work in PHP.)
When in IIS-management I go to the PHP manager, and try to activate the sybase extension (php_sybase_ct.dll). It gets transferred to the activated group, but when I run my script I keep getting "undefined function sybase_pconnect();"
What am I doing wrong? The .dll is in place, it is activated in the .ini file. What is the problem?
Hope someone can help me, cause from looking around the internet, I've seen a lot of problems with PHP and sybase.
The PHP client download page for Sybase states
The PHP modules require SQL Anywhere 10.0.1.3767 or greater.*
You can download the SQL Anywhere database client here.
If the SQL Anywhere client libraries are missing (or not found by PHP), you'd get exactly the symptoms you're getting.
I have on my local PC installed WAMP environment (using WampServer OS).
Now I would need to change one script from working with MySQL to MSSQL.
I have no idea at all how to proceed, where to download MSSQL, how to install it and how to connect with PHP?
Thank you very much
Download mssql express http://www.microsoft.com/Sqlserver/2005/en/us/express.aspx
Familiarize yourself with one of the great database abstraction layers, for example PDO http://www.php.net/pdo
Refactor your code to use the database abstraction layer
You may need to rewrite the mysql specific things to "standard" SQL
Start by getting Sql Server working. If you are using an old copy of Sql Server (pre 2005) you will need to make sure ntwdblib.dll is present in your System32 directory, and removed from your PHP dll directory (ntwdblib.dll is installed with the enterprise tools, so you may have to install them on your PHP box as well). Once you have Mssql querying properly, start finding where Mssql differs from MySql in your code.
A couple of tips:
The ntwdblib doesn't accept long strings (I think it is limited to 4k, but don't quote me on that). You have to use Stored Procs if you are trying to process a string longer than 4k.
Try to use Sql Server 2005 if you can (see above), the ntwdblib.dll is ancient and has numerous issues.
The PHP site is your friend for mssql.