Change PDO driver - php

I'm trying to make my own website with MySQL database. Making it using MAMP was a great succes for me, so I bought Raspberry Pi (Raspbian on board) to make a server from it (and learn ofc). Apache2 is working, php5 also, MariaDB is installed and seems to be working (I can use statements in terminal), but phpinfo() says, that there is no PDO driver. When I install SQLite, it becomes driver with no issue at all (but I want to use MySQL).
So my question is: How to force php (apache?) to make MySQL his PDO driver?
Googling and looking for solutions for days is killing me.
EDIT:sudo apt-get install php5-mysql has Depends: libmysqlclient18 but it is not installable issue. Also I have multiple php.ini files in /etc/php5 (more folders here with php.ini files). Which is the "chosen one"?

Related

How to install phpMyAdmin only with PHP7.3 on Ubuntu 18.04?

I have an Ubuntu 18.04 server with Apache, PHP7.3, and MariaDB.
Now I need to install phpmyadmin and I tried to do that using the code below:
apt install phpmyadmin
But this command will install and replace the PHP7.4 with PHP7.3, whereas I need to keep using PHP7.3.
How can I do this?
How have you installed PHP 7.4, since Ubuntu Bionic (18.04) includes PHP 7.2 (https://packages.ubuntu.com/bionic/php)?
You seem to have gone outside of the standard packages (perhaps you're using the excellent effots provided by Ondřej Surý at https://deb.sury.org/). In this case, it's going to cause you some amount of grief to mix and match the newer PHP with the distribution's phpMyAdmin, because of these dependency problems.
You could force the matter. This is probably going to cause you problems, since Bionic packages phpMyAdmin 4.6.6, which is only supported up to PHP 7.1. https://serverfault.com/questions/250224/how-do-i-get-apt-get-to-ignore-some-dependencies has some instructions on ignoring the dependencies. I recommend avoiding this solution.
You could install your own phpMyAdmin. Download the source from phpmyadmin.net and uncompress it to your web root. You may need to add a short configuration file, config.inc.php, but mostly it just works with the default settings. https://docs.phpmyadmin.net/en/latest/setup.html has a quick start section.
You could downgrade your PHP, but you've already stated this isn't a good option for you, and I'm not sure how the Ubuntu package managers get phpMyAdmin working with this newer PHP version.
Clearly, I think the best solution for you to is to install your own phpMyAdmin.

How do I install PHP PDO ODBC drivers on CentOS 7?

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.

Php pdo mysql not found

I have already done much digging on installing/enabling PDO mysql extension on stackoverflow and many other sites, so please do not consider this as a duplicate question
I am on centos 6.5 and has php 5.5.26 which was compiled with make, make install (I know this is an older version so please do not close question or suggest updating to new php version. Also cannot install php using yum as this is what has been installed already me and should not be installed/changed).
So when I did compile php and added it to apache, it does not show mysql PDO driver. I tried putting extension=pdo_mysql.so to ini file with no success (yes I did restart the server as well, after making changes).
It shows pdo enabled, but only for drivers pgsql and sqlite.
Also, tried installing php-mysql package using yum. But the issue with yum installation is it installs 5.3.3 version of driver which complains about compatibility issues as my php version is 5.5.26.
So I am not sure what I need to do install pdo mysql extension
#Peter Darmis was right from his comments.
PHP 5.3.3 was not completely uninstalled, don't know why.
There was already a PHP installed manually be compilation and, as I wasn't aware about this, I was using yum for installation of modules and at that time PHP 5.3.3 got installed which I don't know why it dot un-install properly.
So I ended up with 2 PHP versions, so uninstalled PHP 5.3.3 completely using yum and then resolved this issue compiling PHP with pdo options

(Linux) PDO cannot find the MySQL driver

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.

Can't find MySQL driver anymore (Linux)

Today some of my packages in Ubuntu was upgraded automatically, and I didn't think of what was actually going on.
Ever since the update, my local dev-environment doesn't work anymore. First of by not working was mod_rewrite which I had to enable again using a2enmod. But now I've run into an issue that I can't seem to resolve. My application can't seem to find the PDO MySQL driver. When running the application, I get the error failed to open the DB connection: could not find driver.
This is strange, since if I check the phpinfo() the PDO drivers do support MySQL, and the socket path is a valid path.
pdo_mysql client API version is 5.5.35 according to php info.
PHP5: 5.5.3
MySQL: 5.5.35
Connectionstring
mysql:host=127.0.0.1;dbname=MyDB;port=3306
What could be causing this?
The PHP MySQL driver (mysql.so/mysqli.so) and the PHP PDO MySQL driver (pdo_mysql.so) are two separate modules. You need both of them for PDO functionality with MySQL.
It is quite possible that one of them is missing or of an incompatible version - I do not have an Ubuntu system at hand, but on my RPM-based Linux distribution there is a separate package for each module (php-mysql/php-mysqli and php-pdo_mysql). I also expect PDO to be using the newer mysqli.so driver, rather than the obsolete mysql.so one, so you should verify that one is installed as well.
Try this:
sudo apt-get install -y php5-mysql php5 mysql-client
This should automatically restart your apache if any of the dependencies aren't installed.
Try using vagrant.
Dependencies can be isolated, upgraded and downgraded when you like.
Vagrant

Categories