I've been googling and searching SO for the better part of an hour, and fail to find a good answer. I'm a server admin noob here, so I'm sure this is not too difficult, but I sure don't know what to do.
Info:
Running PHP5.3.6 on an Apache server, using WHM/cPanel as the server admin GUI
I'm trying to connect to a client's MsSQL database, and alas, get the following error:
Fatal error: Call to undefined function mssql_connect()
So I start googling, see that perhaps that's not the best function to use anyway. Alright, so I look at PHPinfo for PDO support:
PDO drivers sqlite, sqlite2, mysql
How on earth do I get mssql to show up in that list, so I can do something like the following:
$dbh = new PDO("mssql:host=host.name;dbname=name", 'user', 'pass');
I can't seem to google my way out of this one. Any thoughts?
You can uncomment the "extension=php_pdo_mssql.dll" line in php.ini if you have access to it.
If it still doesn't work, you might want to try this (once again, only if you have access to it):
ntwdblib.dll - The most common issue is that you do not have the
ntwdblib.dll file installed in your PHP directory (where php.exe is,
or sometimes placing it in the ext directory works as well). This
library can be found with your Enterprise Manager dll's or in your SQL
servers system32 folder. It's generally best to take the file from the
server where SQL Server is installed -quoted from
http://www.helpspot.com/helpdesk/index.php?pg=kb.page&id=13
If you are doing this on some kind of rented hosting (IE: Shared Hosting) you may need to contact the support from the hosting provider to get them to enable it if you can't get it to work.
http://us.php.net/mssql also has a lot of information. The installation is what I just stated above, but the user comments address a lot of more unique situations and provide more detail.
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 am trying to use the yii framework for a while. I have been referring - first-app-doc and yiic-doc.
I have read all the posts related to mine on "stackoverflow" but couldn't get any luck resolving my problem. Mostly because I am stuck on the .ini files and the pdo.
I have modified the config file-protected/config/main.php according to my database configuration. I am using the command line tool - yiic to create the model. It gives me 'http://hostname/path/to/index.php?r=user' to hit.
When I hit http://localhost/index.php?r=user; it gives CDbException - CDbConnection failed to open the DB connection: could not find driver in the browser itself. It seems like it can't find the pdo_mysql.
Also, I don't have the php.ini file in /etc/php5/, but I have different php.ini files in /etc/php5/cgi/, /etc/php5/apache2/ and /etc/php5/cli/.
Also, the php5-mysql package, I have it installed on my computer.
I have been trying and trying. This is like impossible to do.
I know this is a little old question now but hopefully it can help other people, I actually had the same issue I was using it on Google Compute engine where we set up the server and we found out you have to install sqlite PDO extension as well as the MySQL PDO extension.
More information is on my question: https://stackoverflow.com/a/24555366/817213
Hopefully this can help other people too.
1- try to access the database with MAMP or WAMP or XAMP, or even by command line first. you will then know if you need a username and password for that.
2- check what databases you have. you will know then if the database exists or not.
3- check the database connection string in the project if it's correct or not.
I really feel like I have done an exhaustive search on this matter, found similar issues and have tried a number of things without success, so I am for the first time posting a question here:
I do a lot of web pages/web programming (PHP/jQuery mostly) and host these pages on my digital library department's Drupal/Ubuntu Server. I just code them and post them via Dreamweaver, as I don't have much use for the Drupal front end. I just need the server for my pages.
Anyway, I am wanting to make some PHP pages that can connect to our library catalog, so I have been working from the command line of the Drupal/Ubuntu server. I installed unixODBC, had some troubles, installed FreeTDS, set up the drivers and the DSN.
Finally...
I was able to get a connection to our catalog via tsql and run a query.
I made a basic PHP script to test the connection:
It works from the Ubuntu command line of the server (connection successful).
It doesn't work when I load it in a browser. I get the dreaded:
Warning: odbc_pconnect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /var/www/mydirectory/mytestpage.php on line 15
UPDATE: I installed a test Ubuntu Server in a partition on my laptop, where I started clean, installed Apache2/PHP5(with mssql and odbc modules, etc)/FreeTDS, etc. I got a tsql connection. I made the basic PHP script and ran it successfully from the command line. Then I navigated to the php page from a browser and it worked! I still need to get this to happen on the Drupal server version, but now I have at least narrowed down the issue to something on the Drupal server.
I searched and found such possible causes as:
File permissions, which I think I got corrected, but no go
That maybe I had set up a User DNS and not a System DNS which I tried my best to correct with the proper "odbcinst" command options
That maybe php needs to be running in CGI mode instead of as a module. But that seemed unlikely from what I read. And I am not sure how that would affect Drupal. (There are limits to the system wide changes I should make here.)
A number of people said it was SElinux blocking Apache from displaying the page in the browser, but temporarily disabling SElinux didn't work.
Thanks for any assistance!
Check you have enabled the mssql.so etc at the following location
/etc/php5/apache2/php.ini, you will be having another at /etc/php5/cli/php.ini
in ubuntu php.ini will be maintained separately for cli & mod_php apache configuration
If you are going to test your odbc sources on the commandline, I would advise you use the isql utility instead of tsql. isql uses the DSN you defined in odbc.ini to connect to the database, while tsql connects directly to your database.
If it works with isql, it should work on your webpage as well.
Also check the Drupal/Ubuntu Server files /etc/odbc.ini (your DSN sources) and /etc/odbcinst.ini (TDS Driver settings) to see if they match the ones on the working Ubuntu installation.
My guess is it has something to do with the php. ini file. On my Ubuntu system I've got 2.
One in /etc/php5/apache2/php.ini
And one in /etc/php5/cgi/php.ini
The values in the apache2 path will need to be adjusted to allow the connection. Unfortunately outside of that I'm not too much use as I use MySQL and Mongo
Copy your php.ini from work server to non-work server, add make needed environment variables accessible before starting your web server, and make sure your web-server has full access to your odbc and odbcinst ini-files. And so, using mssql knowledge base or help.
I'm sure this is something simple that I'm overlooking, but it's driving me a bit crazy. I'm on a Ubuntu machine running LAMP. I have several sites running on this machine using Php / MySql without a hassle. I've recently begun a site using the Yii framework, but I don't think that this is a Yii quesiton. Maybe it is. Anyway...
My other sites used mysqli so Yii's PDO requirement is new to me. I did a quick -i|grep on the PDO and it came back as installed / enabled so no worries. I installed the framework, created a quick test site and database. However, when I try to connect to the database via the site I get an error telling me that the PDO failed. Specifically, a failure to open the stream. So it's not finding the PDO even though the PDO is installed. The Yii site is in the same web folder as the other sites, so there can't be a path issue.
From a Yii standpoint, if that is where the problem lies... I was able to create controllers for the various database tables in Gii, but pulled the same unable to open stream error when I tried to generate CRUD for those tables.
For the record, yes, the MySql is enabled in the Yii main.php file. Yes, the connection string is correct. I'm a bit at a loss as to why the PDO would fail to open if it lists as enabled.
Posting this just for the search engines. I still have no idea exactly what the problem might have been. As I mentioned, PDO was showing enabled from the CLI, but not from phpinfo. This is possible because the CLI uses a different php.ini than does apache2. However, after a complete re-install of php I was still running into the same problem. I again opened both .ini files in gedit and went line by line with them using a non-case sensitive find on "pdo". They were absolutely, completely identical. Finally, I gave up trying to understand the problem and just went for the easy fix. I removed the .ini from Apache2 and replaced it with the one from cli, and voila! I have PDO enabled in Apache2. I still have absolutely no idea what the problem was, but at least it's solved.
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!