I'll start off by saying I am thoroughly confused. I've read through "The Underground PHP and Oracle Manual White Paper" and through some similar questions on StackOverflow and I still have no idea what I need to do.
I'm using PHP 5.3.1 on Ubuntu 12.04. I'm trying to connect to Oracle 11g. I don't know if I need Instant Client or Oracle XE. I want to connect to it using PDO as that's how my code is already structured but I can't make heads or tails of the documentation. I also have an option to connect via ODBC. Any help would be greatly appreciated.
In any way, you need at least instant client if you are connecting with PDO.
Oracle XE contains OCI runtime (Oracle call interface), but you may need to setup some environment variables to make it work.
Is it Oracle XE instance on same server as Apache/PHP ?
You have couple of good articles on google's search result like:
http://www.sitepoint.com/oracle-10g-xe-and-php/
http://docs.oracle.com/cd/E17781_01/appdev.112/e18555/ch_one.htm
http://web3us.com/drupal6/how-create-web-site-handbook/oracle-xe-php [Recommended reading]
http://www.devshed.com/c/a/Oracle/Configuring-Oracle-Database-XE-and-PHP/
http://php.net/manual/en/function.oci-connect.php
Related
I am currently creating a PHP script to copy some data onto a Microsoft SQL server from a MySQL server. I decided to use PHP with PDO since I thought it would be a really quick process (famous last words).
The Mysql side is completed but I am completely stuck on the MS SQL side on how to get everything installed correctly. My work script server has several different drivers installed (freeTDS, Microsoft ODBC Drivers) and I am not sure how to setup this new MS SQL server in PHP especially to use PDO instead of the direct ODBC functions PHP has.
The work server uses PHP 5.3 which has caused problems with perl rejecting to install sqlsrv/pdo_sqlsrv since the server doesn't run PHP 7.1 or greater.
My main questions being:
Which driver should I use to setup the PHP 5.3 MSsql driver on a redhat server that will work with PDO?
What should my PDO connection string look like?
This is what I have now:
$connectString = "sqlsrv:server=$host;Database=$schema;charset=$charset";
Is it really necessary to define the server connection in the ODBC driver before hand?
Sorry I don't have more research into this it seems there are many ways to bring in MSsql in PHP and I'm not sure which path to go down for my specific version of PHP!
I use this for MSSQL connection with pdo
$db = new PDO("sqlsrv:SERVER=$dbhost;DATABASE=$dbname", $dbuser, $dbpassword);
I was trying to connect to a Microsoft SQL Database with PHP using the mssql set of functions that WERE in php. Since I am using php 5.5, these functions are deprecated I think, but I read that there is a solution, which is downloading the drivers windows is providing. I downloaded and installed them from the following link:
https://www.microsoft.com/en-us/download/details.aspx?id=20098
Now the only thing is unclear to me is how to use them. Do these drivers re-activate the mssql (which I am sure it is not the case since I tried the code using mssql_connect and it threw a php error saying that the function could not be found)?
Can anybody give me an example of a MSSQL connection with these drivers?
Thanks a lot for your time and help!
Cheers!
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.
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!
How do I connect to a remote Oracle database instance from PHP?
I need to query (read only) the remote Oracle database for some information; do I need to have an Oracle Instant Client installed?
Is the OCI extension for PHP enough?
From PHP Manual
You will need the Oracle client libraries to use this extension.
The most convenient way to install all the required files is to use Oracle Instant Client, which is available from Oracle's site
The best manual for using PHP with Oracle is Underground PHP Oracle Manual. Periodically updated. For example last update describe new cool OCI (Oracle Call Interface) features. I found it by accident and since then has never regretted. Start from that good manual.
there are a couple of steps you need to go through to make this work.
First, you need to install the oracle driver for whatever OS you have. Then, create a DSN for odbc to use to connect the php function call to the oracle database. On windows, you can find this on the Control Panel -> ODBC Sources
Once you have done this, restart the DB, the web server and then you should be able to test it all with this:
odbc_connect($dsn,$user,$pass);
If you have linux, the same steps are needed but I'm not sure how you create a DSN in unix.
I saw this in the "Notes" section of the PHP documentation:
If you're using PHP with Oracle Instant Client, you can use easy connect naming method (...)
So I think it's rather clear that you can connect to an Oracle DB without the Oracle Instant Client, using only the PHP Oracle extension.
If you're attempting to connect to oracle on ubuntu with PHP, the following links have been more than helpful:
A) http://pecl.php.net/bugs/bug.php?id=9253
That's the real-workhorse one - it gives you just about all the data you need.
B) http://fabrizioballiano.net/2008/01/26/how-to-install-php-pdo_oci-on-ubuntu-gutsy/
This is also helpful for details of things that need to be installed for oracle to work with ubuntu.
If you're using it with PHP, you'll need to make sure that the TNS_ADMIN and ORACLE_HOME environment variables are available for apache's user - there's a file named 'envvars' in the apache2 directory where you can set these. (For my own ease of use, I have the two point to the same directory.)