I have been using oci_ in PHP but I would like to start using PDO.
I have read http://www.php.net/manual/en/ref.pdo-oci.php but I'm not sure how to enable PDO_OCI. I see the command listed on the page but I installed PHP using sudo apt-get install php5 and not via the source.
<?php
print_r(PDO::getAvailableDrivers());
?>
shows
Array
(
[0] => mysql
)
Can someone help as the PHP website does not have much information other than that single command? I understand it is experimental but I would like to try it, I just can't find much information on it.
Install the PDO_OCI drivers using pecl. This tutorial may help: Installing PHP & Oracle PDO Drivers on Ubuntu
Related
I already have PHP 5.4 installed in a CentOS 7 VPS. I am trying now to access a legacy database in .mdb format with a PHP script.
However, my phpinfo() page says that only mysql and sqlite PDO drivers are enabled. No driver named ODBC is enabled.
Which is why I have tried to follow this tutorial to get that to work. But it doesn't work. bash: ./configure: No such file or directory.
I don't know from which folder I have to run the commands listed there. Is there a command which will allow me to install the PDO ODBC drivers from the system e.g. yum -y install php_odbc which would be easier for me to work with? If not, what am I doing wrong?
Looks like php_odbc is one of CentOS 7 packages.
See http://mirror.centos.org/centos/7/os/x86_64/Packages/ it is a very long list.
So yum -y install php_odbc should work. Just don't forget to restart your web-server if required.
You would run ./configure ... if you were compiling PHP from source. It will not work in your case.
So basically I have been always developing with PHP under Windows with the WAMP package and I never had any trouble.
Now, I am trying to transition to Linux (Mint). Everything is well, except for the PDO extension which cannot find the MySQL driver. In fact, it states not having any available drivers at all.
First, I installed Apache:
sudo apt-get install apache2
Then, PHP:
sudo apt-get install php5
MySQL for PHP (I am not exactly sure this was required):
sudo apt-get install php5-mysql
Finally, the command line interface for PHP:
sudo apt-get install php5-cli
Note that I had installed MySQL a while ago for other purposes.
Everything else is working well. The server starts, runs, executes scripts. I am also able to create an instance of PDO, but then it throws a PDOException stating that it cannot find the MySQL driver. The code is typical of a PDO initialization :
$pdo = new PDO("mysql:host=127.0.0.1;db=testdb", "root", "");
I looked at the phpinfo() and for the value PDO I see no drivers. However, I see the line MySQL driver for PDO followed by the names of its authors, but I cannot tell if it guarantees the presence of the driver. Notice that I also see the authors of all the other drivers (SQLite, PostgreSQL, Oracle, etc.).
The command php -m (which, according to the php --help, lists all modules compiled with PHP) also clearly indicates that both PDO and pdo_mysql are installed.
My search returned a lot of results about the extensions pdo.so and pdo-mysql.so. I have been trying to reference them into the php.ini file without success. It would probably have a higher chance of success if I actually had these files, but so far I have been unable to find them.
So, here we are, about five hours later, with me being completely stuck.
Thank you.
I installed unixODBC by using apt-get install, and now when I try to use odbc_connect() is still get this error.
PHP Fatal error: Call to undefined function odbc_connect()
what do i need to do to configure it to work with php? I have been looking online but I can't really figure it out.
I think you need to install php5-odbc also. unixODBC provides the driver manager, but you need the PHP code that calls it.
Had the same issue on CentOS 6.3 with PHP 5.3.16. But the fix was to use yum to install php-odbc.
yum install php-odbc
Did you add it to your LD_LIBRARY_PATH? Check the documentation for your server, it may require third-party libraries to be in a specific sub-directory, or have some other mechanism for finding them. If so, you should be able to create a symbolic link to the library. That way, if it gets updated, your server will automatically use it.
We had this problem also. We installed php5-odbc, and still had the problem. Turns out we needed to reboot Linux for php to see the function. Recycling Apache was not enough!
Make sure to enable odbc extension for your Apache by a2enmod odbc.
Then check if exists by: apache2ctl -M.
If you don't have this extension, install via apt-get install php-odbc (use yum in case of CentOS).
See also: Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS.
I encounter this problem when configure PHP and mysql on my linux box (Fedora 14).
The problem is when I invoke mysqli_connect(), an error issues:
Call to undefined function mysqli_connect().
while call to mysql_connect() works fine.
I install PHP and mysql manually and also turn on the flag --with-mysql when installing PHP. Can't figure out where things go wrong.
Mysql-i is not Mysql, these are 2 distinct PHP modules and MySQL APIs. Have a look at PHP's documentation regarding the mysqli installation.
If yum is an option for you, you can simply run the following to install the mysqli extenstion:
yum install php-mysqli
EDIT: Marc B informs that mysqli is included in the core php rpm on Fedora 14. Simply install php via yum (after removing your manual install) with yum install php
http://php.net/manual/en/mysqli.installation.php says:
To use MySQL Native Driver with mysqli you need to configure the PHP source code using the --with-mysqli=mysqlnd option, prior to building PHP.
In other words, --with-mysql is for a different module (which, as you note, works fine).
Does anyone know how, on Ubuntu 8.04, with PHP 5 and MySQL 5.0, to enable/install the mysqli package/extensions?
Preferably I'd like to preserve the existing installations, but, if necessary, I'll reinstall from scratch.
I realise it's not, technically, programming-related but, I think (at a stretch, maybe) it's programming-enabling? hopes
Thanks for any help you're able to provide.
In Ubuntu Hardy (8.04) mysqli is part of the php5-mysql package along with the standard mysql library and pdo - see http://packages.ubuntu.com/hardy/php5-mysql for more info.
sudo apt-get install php5-mysql
You might have to install php with the mysqli option: apt-get install php5-mysqli
From the PHP documentation.
To ensure that the mysqli extension for PHP is enabled, you will need to configure the PHP source code to use mysqli. This is achieved by running the configure script with the option --with-mysqli=mysql_config_path/mysql_config, prior to building PHP. This will enable mysqli and it will use the MySQL Client Library (libmysql) to communicate with the MySQL Server.
But since you are on ubuntu. You can just install the mysqli package. Details about it here.
sudo apt-get install php5-mysqli
With PHP5 php5-mysqli package is not available, but it is replaced by another package. May be package is obsolete.
It can be downloaded by the following command
sudo apt-get install php5-mysqlnd