unixODBC Freetds PHP Problem - php

I am using Debian. I have unixODBC installed as well as FreeTDS. I am using PHP
I have read several How-Tos and am stuck on a problem.
I tested FreeTDS by using tsql and it works.
I tested unixODBC by using isql and it works.
When I created a script in PHP and tried to access a database I get the following errors.
Fatal error: Call to undefined function odbc_connect()
I have found multiple php.ini files. Which is the one that Apache2 uses? Is there something in there that needs to be set.
Is there some setting that I missed seting that was not in the How-Tos?
All help is greatly appreciated.

You may need to provide environment variables to point to the location of your ODBC configuration files:
<?php
putenv("FREETDSCONF=/etc/freetds/freetds.conf");
putenv("ODBCSYSINI=/etc/odbcinst.ini");
putenv("ODBCINI=/etc/odbc.ini");
This works for me to connect to several ODBC databases. (Your config files might be somewhere else)

You need to install php5-mssql and/or php5-odbc.
I'd recommend you to install both just for sure.
Files from /etc/php5/conf.d/ and /etc/php5/apache2/php.ini used to store PHP configuration options in Debian.

Related

Weird case of notorious error "could not find driver" from Laravel

It looks like my Laravel deliberately ignores API extensions set in my php.ini
since I’m getting could not find driver (SQL: select * from ....
php.ini is configured properly and php artisan migrate works fine and I can see its job im my MySQL DB.
Trying to figure out what goes wrong I added phpinfo() into default route and saw this:
API Extensions = no value
PDO drivers = no value
However, if I start project by php -S localhost:8000 -t public/ instead of php artisan serve the everything works fine and API Extensions has pdo_mysql and PDO drivers = mysql.
In both cases Loaded Configuration File is the same C:\php\php.ini
What's wrong with Laravel?
PS. Laravel 5.5, php 7.1
Laravel uses the php cli's inbuilt server which can have a different set of enabled extensions than that of the server(fpm or otherwise). Make sure you are editing the correct php.ini this varies on each os and if using linux each distribution. So I can't give the location of your php.ini but there are multiple for any given installation. Usually one for the cli and one for the server bit. The php -S seems to behave the same as using a webserver at least for me
same php.ini is being used

How can I use mssql functions on php? I don't have php_mssql.dll in my extensions folder

I'm trying to use SQL Server with PHP but I don't know how to install this feature. I have enabled extension=php_mssql.dll in my php.ini file but after restarting apache I got a error message saying that don't found the DLL file.
After much attempts I reinstalled XAMPP 1.81, and I'm starting now from zero.
Thanks for any help.
Edit MSSQL has been discontinued as of 5.3
I believe the correct driver is php_sqlsrv.dll.
http://www.php.net/manual/en/sqlsrv.installation.php
Here are the available functions: http://www.php.net/manual/en/ref.sqlsrv.php

How to connect to Sybase via PHP

I'm trying to connect to a Sybase database with PHP5. I believe I've successfully compiled PHP with PDO_DBLIB, as phpinfo() lists dblib under PDO drivers, and freetds as the pdo_dblib flavour.
However, when I try to test a connection, I get an error reading:
'PDOException' with message 'could not find driver'
I'm trying to connect to a server on my LAN with this code:
$dbh = new PDO("sybase:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
Any suggestions would be greatly appreciated!
You should use dblib instead of sybase, like this:
$dbh = new PDO("dblib:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
PDO wouldn't work, or at least there is no PDO Sybase support for php. On Windows, you can use ODBC, and PDO_SQLSRV or PDO_ODBC, it might sound weird, but it should work.
Second option and I would recommend it, is to connect directly to Sybase (SqlAnywhere), but you need to install SQL Anywhere PHP Module
If you are using Ubuntu you can put the LD_LIBRARY_PATH inside envvars and it seems to read... still trying to find a way to get it to stick on RHEL based systems... Windows I am not too sure about I would hope you could set a system wide variable under
my computer -> properties -> advanced options
If are using RHEL based systems it might be better to include the:
export LD_LIBRARY_PATH=/path/to/library/ in the httpd restart script (check to see if it loads /etc/sysconfig/httpd and if so add the line in there - now restart apache and you should see some activity.

db2_connect to as400 with php and wamp server

I have been trying to connect to a ibm db2 database but it seems impposible. The as400 is in a different server than the one running php.
Everytime I do a db2_connect I get the following error:
Fatal error: Call to undefined function db2_connect()
How can I make this function work?
Tip: I've already tried with odbc and it was a lost of time, but I'm open to suggestions on that path as well.
[EDIT]
I finally changed to java... it was impossible with php...
Check your php.ini file and make sure it has the DB2 extension enabled. http://www.php.net/manual/en/install.pecl.php
Try this link:
http://www.theregister.co.uk/2006/08/09/db2_udb_part2/
Deals with:
Installing the PHP DB2 extension,
Creating a connection,
Obtaining a result set
Also gives as an alternative the PDO option.
But as for DB2 on the AS400, am not sure if something still needs to be installed on the
AS400 for this to work?
Anyway, have used the ODBC Client Access with no problems at all. What difficulty did you run into?

How to set up OCI to connect to Oracle from PHP?

On the latest Ubuntu, I have a functioning PHP 5.2.4 installation. I want to use a remote Oracle server from PHP using OCI.
I've downloaded the "Instant Client Package - Basic Lite" (Link). I've unzipped the package containing the OCI libraries to a dir but I have no idea how to tell PHP that I want to use these libraries. Predictably, I get
Fatal error: Call to undefined function oci_connect() in...
when running this code:
<?php
$conn = oci_connect('hr', 'hrpw', 'someremotehost');
?>
I don't want to recompile PHP with Oracle support. What's the fastest way to wire up PHP so that I can use Oracle? Do I need any other libaries, like the Oracle client if I want to connect to a remote Oracle instance?
You need the PHP extension, try the following on your Ubuntu:
(sudo) pecl install oci8
Make sure your php.ini's (there should be one for your Apache and one for cli php) contain extension=oci8.so afterwards. Finally, you have to restart Apache and can confirm via <?php phpinfo(); ?> that the extension is loaded.
UPDATE:
Enter something like this when it asks you for ORACLE_HOME:
instantclient,/opt/oracle/instantclient
I think setting the environment variable would be another solution. /opt/oracle... is the path I put my instantclient in. I followed some tutorial a while ago, unfortunately I can't find it anmore.
HTH
I think you'll need to make sure that the $ORACLE_HOME/lib32 is in your $LD_LIBRARY_PATH, or else add that directory to the /etc/ld.so.conf file.
In the end, I downloaded Zend Core for Oracle and that worked.
http://www.zend.com/en/products/core/for-oracle

Categories