I have installed FreeTDS on my Mac, but I'm having some issues connecting using mssql_connect.
First, when I run tsql -C I see that the freetds.conf directory is listed as /opt/local/etc/freetds. I have a freetds.conf file inside this directory.
Next, if I connect like this:
$connect = mssql_connect('IP_ADDRESS', 'username', 'password');
then everything works as expected. That is, I can retrieve, update, insert data from/into whichever DB I select with mssql_select_db().
If I try to connect like this:
$connect = mssql_connect('DSN_NAME', 'username', 'password');
where DSN_NAME matches a datasource specified in my freetds.conf file then I get an error and unable to connect to server: DSN_NAME which tells me that PHP isn't correctly seeing the path to my freetds.conf file.
However, if before my call I add:
putenv("FREETDSCONF=/opt/local/etc/freetds/freetds.conf");
then everything works as expected. This tells me that my freetds.conf file is formatted correctly.
I've searched all over about how to find the path that PHP thinks the freetds.conf file is in, but I can't find that.
Lastly, there are some reasons I don't want to use the IP address directly in my connection as well as why I don't want to be forced to use the putenv() method to specify the directory.
Any ideas?
Thank you.
When I installed FreeTDS I originally used MacPorts. I believe that this gave me some conflicts for where freetds.conf should have been. And even though the path for freetds.conf when running tsql -C was the actual path that I was attempting to use, when I compiled the mssql.so extension with that path PHP wouldn't recognize it.
The solution is to forget MacPorts for FreeTDS and just install FreeTDS from source. Then install the mssql.so extension from the PHP source and make sure you're using the same version that is on your system (mine was 5.3.13 under OS X Mountain Lion).
If you follow the instructions at this blog exactly you shouldn't have any issues.
A couple of final things:
I am NOT running MAMP even though the instructions mention it so it won't matter either way.
If you already did install FreeTDS via MacPorts, uninstall using: sudo port uninstall freetds +odbc and then sudo port uninstall unixODBC. Make sure you uninstall all instances of FreeTDS. If you have more than one, you'll get a notice when you run uninstall that you need to specify the version to uninstall.
Related
I am trying to connect to a Azure data base. I have read many other stack overflow answers but they did not work for me:
-I have downloaded all the drivers that Azure offers to you. They are in
C:\wamp\bin\php\php5.5.12\ext folder:
-I have added to the system variable the path to extensions folder.
-I have set the extension in both php.ini files (inside the apache and php folders).
-Extensions have been set like
extension=php_sqlsrv_5X_ts.dll
extension=php_pdo_sqlsrv_5X_ts.dll and like extension=C:/wamp/bin/php/php5.5.12/ext/php_sqlsrv_5X_ts.dll extension=C:/wamp/bin/php/php5.5.12/ext/php_pdo_5X_ts.dll
Where X means that I have tried 53, 54, 55 and 56.
-I restart all wamp services every single time that I try new changes.
-I have even tried with IISExpress.
-It is still giving me this error and I can't see "sqlsvr" when I use phpinfo().
what more I should do? I have been suffering this for weeks.
I use this XAMPP with PHP 5.5.34 at https://www.apachefriends.org/download.html to have the test to enable the sqlsrv extension of PHP.
You can refer my steps:
After install the XAMPP application, run xampp-control.exe, click config=>PHP(php.ini) to check the extension folder.
Download the MSSQL driver for PHP in 3.2 version from https://msdn.microsoft.com/en-us/library/cc296170%28v=sql.105%29.aspx?f=255&MSPPError=-2147217396. Uncompress it.
Copy php_pdo_sqlsrv_55_ts.dll and php_sqlsrv_55_ts.dll from the uncompressed driver folder to the PHP extension folder (X:\xampp\php\ext in my scenario).
Add extension=php_pdo_sqlsrv_55_ts.dll and extension=php_sqlsrv_55_ts.dll in PHP.ini file.
Start Apache.
Meanwhile, you can use phpinfo() to check the setting of Loaded Configuration File and extension_dir to make sure whether you have configured the correct settings in the definite files and the DLL files in the right folder.
I refer to the practice of Jordi's message in this post: Fatal error:
Call to undefined function sqlsrv_connect() in C:\xampp\htdocs
xampp3.2.1 + php 5.5 + sql server 2014 Express, x64.
My situation is, transplant xampp folder to a brand new computer.
Done all things need to do. (Download SQLSRV 5.6 (or 5.3 or..), check php.ini path, ...)
Download and install OBDC Driver 13(x64) (or maybe you can try OBDC Driver 11(x64))
Download and install SQL ServerĀ® 2014 Service Pack 3 (x64), need to restart the computer.
Download and install Visual C++ Redistributable VS2012 Update4 (x86)
Restart Apache
Then it can work!!!!!
I have been searching for a solution to this problem for several days and hope to help more people.
We updated FreeTDS on our CentOS box and can connect using tsql cli.
Before the update, tsql -C reported 0.91 and now it reports 0.95.
The new versions is using a freetds.conf found in /usr/local/etc instead of the old /etc/ directory.
PHP using PDO is still referencing the old freetds and the old freetds.conf. I know this because changing the old freetds.conf is still affecting our PHP scripts/
How do we get PHP and PDO to use the new freetds.
You have a few options.
Copy the old version in /etc to the new location 0.95 is looking for in /usr/local/etc
Make a symbolic link to the old location from the new: ln -S /etc/freetds.conf /usr/local/etc/freetds.conf
FreeTDS also looks for a .freetds.conf (notice the "." at the beginning) in the home directory of the current user. You could put a .freetds.conf into the directory of the user your web server runs as.
Finally, you could compile from source if you want version 0.95, passing the option --sysconfdir /etc to the configure command before compiling.
More info: http://www.freetds.org/userguide/freetdsconf.htm
Good luck!
I have to create PHP web service with Firebird db. This is the first time I configure connection with this db and I cant get it right.
I followed every instructions from php manual site, copied neccesry dll files to win/syste32 folder etc. and it's not working.
I dont understand this part:
Use --with-pdo-firebird[=DIR]
to install the PDO Firebird extension, where the optional [=DIR] is the Firebird base install directory.
$ ./configure --with-pdo-firebird
Where should I run this?
These instructions only apply to building PHP from source.
On Windows, you should find that a php_pdo_firebird.dll file is included in the installation package in the ext directory, all that is required is to uncomment/add the following line in php.ini:
extension=php_pdo_firebird.dll
You can then check that the driver is enabled in phpinfo(), php -i or with PDO::getAvailableDrivers().
I have Snow Leopard and am using the default apache. I installed postgresql via macports. So now I can do a psql from a terminal (I tried but failed to do a install of php5 through macports but there was an error)
I have enabled php5 and restarted the apache so now I have php. But for the life of me I cannot figure out to hook up postgresql to work with php. I'm trying to do a pg_connect() and I get
"Fatal error: Call to undefined function pg_connect() in /private/var/www/html/sheep/connect.php on line 4"
I have put
extension=pgsql.so
extension=pdo_pgsql.so
In the php.ini file. My phpinfo says my extension_dir=/usr/lib/php/extensions/no-debug-non-zts-20090626
I went to /usr/lib/php/extensions/no-debug-non-zts-20090626 directory on my mac and actually put pgsql.so and pdo_pgsql.so in that directory from MAMP. I did a locate in the terminal for pgsql.so and it existed in my MAMP directory. I don't want to use MAMP anymore but thought maybe I could move the .so file and use it.
Do I have to recompile php with postgresql? Do I have to do something special to get a non MAMP pgsql.so file? I didn't know what pdo_pgsql.so but I thought I would try it so that is why it is in there.
The easiest way is jsut to use all the packages from Macports:
sudo port install apache2 postgresql83 php+postgresql83+mysql5+pear+apache2
Otherwise you are going to have to download source and compile manually... you cant use the binaries provided by mamp unless you use mamp.
How do you connect to Oracle using PHP on MAC OS X?
I would think OCI would be the way to go. PHP has a module for it.
The PDO abstraction layer can be used to connect to, and perform actions on, an Oracle DB. Here's an article on how to use PDO with Oracle from the Oracle website.
It's also possible to use OCI.
The Oracle PHP Development Centre will have lots more useful information on using Oracle and PHP together.
For instantclient on osx 10.6 64bit do the following:
download the instant client librarys and sdk, stuff it all in a folder. Make sure you get the 64 bit library if you are on a 64 bit machine, 32bit won't work!
- test with sqlplus first
create this if it does not exist
sudo vi /etc/launchd.conf
and add to following to the file(with your own path!)
setenv DYLD_LIBRARY_PATH /usr/oracle_instantClient64
You probaby need to restart your system at this point for launchd to pass the path to apache to pick up the path, or see if restarting launchd works, though i have a feeling that will restart your system anyway!
You should add "extension=oci8.so" to php.ini
sudo vi /etc/php.ini
if that file does not exist copy php.ini.default
sudo cp /etc/php.ini.default /etc/php.ini
then add the above extension, there is a section with lots of extensions further down the file, put it there somewhere
oci requires a library symlink so do
sudo ln -s $DYLD_LIBRARY_PATH/libclntsh.dylib.10.1 $DYLD_LIBRARY_PATH/libclntsh.dylib
Also theres some wierd hardcoded library link in the oracle binaries so fix that
mkdir -p /b/227/rdbms/
Its only looking for the oracle libraries so link it back
ln -s /usr/oracle_instantClient64/ /b/227/rdbms/lib
now install oci8 from pear repository. If you have installed snow leopard osx 10.6 without upgrading you may have problems with pear and pecl. If so you will need to install pear first. see: https://discussions.apple.com/thread/2602597?start=0&tstart=0
sudo pecl install oci8
HINT: don't use autodetect, specify the instantclient path when it asks you..
instantclient,/usr/oracle_instantClient64
restart apache
sudo apachectl graceful
test by navigating to the URL in a browser or you can call the file directly on the command line
php index.php
thats it
use the following as a test file..
<?php
$dbHost = "localhostOrDatabaseURL";
$dbHostPort="1521";
$dbServiceName = "servicename";
$usr = "username";
$pswd = "password";
$dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=".$dbHost.")(PORT=".$dbHostPort."))
(CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))";
if(!$dbConn = oci_connect($usr,$pswd,$dbConnStr)){
$err = oci_error();
trigger_error('Could not establish a connection: ' . $err['message'], E_USER_ERROR);
};
$strSQL = "SELECT SYSDATE FROM DUAL";
$stmt = oci_parse($dbConn,$strSQL);
if ( ! oci_execute($stmt) ){
$err = oci_error($stmt);
trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
};
while(oci_fetch($stmt)){
$rslt = oci_result($stmt, 1); print "<h3>query returned: ".$rslt."</h3>";
}
?>
I dont know the Mac specifically, nor PHP, but you usually need to install the Oracle Client tools (Instant Client).
http://www.oracle.com/technology/tech/oci/instantclient/index.html
Once installed you modify the TNSNAMES.ORA file to point to the server and instance name of the Oracle database.
Then you can use the PHP "database connection" stuff (sorry) to create a connection and running your SQL statements.
Use the SQL*PLUS client to check the connection works:
ie.
c:> SQLPLUS
CONNECT scott/tiger#mydatabase
If the TNSNAMES.ORA is correct you should get a connection, or at least "username/password incorrect" that proves you got communication with the Oracle instance.
If you get TNS-12521 (?) errors then your TNSNAMES.ORA is incorrect.
Connecting to an oracle database should be no problem with the oci-interface, using "oci_connect()" for example.
Further examples are here:
http://php.net/manual/en/oci8.setup.php
But I do not understand, what the remark MAC OS X means - are you running an apache locally?
Hope this helps,
Bastian