PDO MySQL Driver on Mac - php

I have a mac with a custom PHP 5 install that built from about a year ago. I remember it took all Sunday and I had to compile about 20 times to get it right. The MySQL I have is from entropy and was precompiled.
Now I need to get PDO with the MySQL driver working and the driver is not installed. I tried the "pecl install pdo_mysql" and it dies at a point where it can't find some mysql files. Any ideas how I can fix this quickly?
checking for mysql_config... not found
configure: error: Cannot find MySQL header files under
ERROR: `/private/tmp/pear/temp/PDO_MYSQL/configure' failed
I'll post whatever paths or messages you need to help me troubleshoot this. Will I have to compile PHP all over again, or can I just compile the pdo_mysql extension?
I hope I don't seem lazy, I just have a lot of code to write and not a lot of time to fight with my PHP configuration.

You're going to need to compile it by hand, instead of via PECL. You'll need to know where your MySQL install is. I don’t know about the Entropy packages, but the builds provided by MySQL (which I recommend) install into /usr/local/mysql.
$ pecl download pdo_mysql
$ tar xzf PDO_MYSQL-1.0.2.tgz
$ cd PDO_MYSQL-1.0.2
$ phpize
$ ./configure --with-pdo-mysql=/usr/local/mysql
$ make && sudo make install
And that should get you to the point where you can configure it.

FYI; the MySQL PDO driver is included in the php 5.2.9 and 5.3 builds from Marc Liyanage's entropy.ch

Related

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.

How to build SQL Relay for PDO from source on windows?

I am trying to integrate SQL Relay with PHP PDO on Windows (WAMP). I have installed and compiled Rudiments and SQL Relay on Windows through Visual Studio Developer Command Prompt following the instructions given on the Rudiments and SQL Relay SourceForge pages.
Then I downloaded the pdo_sqlrelay extension source from github and tried to build the dll for this extension.
In the build instructions, I couldn't find the ones pertaining to Windows specifically. I found instructions related to Linux. They are:
cd /path/to/pdo_sqlrelay
phpize
./configure --with-php-config=/path/to/php-config \
--with-pdo-sqlrelay=/path/to/sqlrelay/prefix \
--with-rudiments=/path/to/rudiments/prefix
make
make install
I tried to convert them to the relative Windows commands by following the step by step php extension build instructions on PHP's Wiki for building for Windows.
When I tried to execute the command, it threw a fatal error. (like undefined or invalid $remains).:
configure --disable-all --enable-cli --enable-$remains
I would appreciate if someone could help me out to build the pdo_sqlrelay extension on Windows.
you need to ...
first run bin\phpsdk_setvars.bat
to set up the build environment, so that $remains will be known as a variable.
then configure the build with buildconf (or buildconf --force for rebuilding).
then configure --disable-all --enable-cli --enable-$remains ... you probably might also want to --disable-zts (depending which PHP is being used).
it's rather nmake to build & nmake clean to clean.
to install & uninstall it's nmake install and nmake uninstall.
the documentation also states ...that:
First build and install Rudiments, then build and install SQL Relay.

(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.

How to install mcrypt on OS X's natively installed PHP?

I am trying to install the mcrypt PHP extension on my OS X Mountain Lion 10.8 operating system. This OS comes shipped with Apache and PHP already installed. The mcrypt extension however does not come shipped with PHP. I want to install mcrypt into the version of PHP that came shipped with my machine.
I do not want to use Homebrew, Macports, or any similar package manager, and I do not want to install another version of PHP in addition to the one I already have. I just want to plug mcrypt into the PHP that came bunded with my OS. I feel like this makes sense, instead of having multiple versions of the same program installed, yet every tutorial I come across seems to all immediately say to use Homebrew/Macports, and the few that don't teach you how to install a new PHP instead of using the one I already have.
I started following the directions laid out on this page: http://www.coolestguyplanettech.com/how-to-install-mcrypt-for-php-on-mac-osx-lion-10-7-development-server/.
I downloaded libmcrypt-2.5.8.tar.gz from Sourceforge.
I extracted the contents with the following command: tar -zxvf libmcrypt-2.5.8.tar.gz.
I entered the libmcrypt-2.5.8 directory that was created and issued the following commands: ./configure, make, and sudo make install.
Now that tutorial says to go into a directory that was created by a new, non-native version of PHP that the tutorial tells you to install, not the native version that came shipped with OS X. The tutorial says to go into the following directory: cd ../php-5.3.13/ext/mcrypt/ (which is a directory I don't have), and run the phpize command. I can't go into that directory because I'm using the native PHP that came with OS X, so instead I go into the libmcrypt-2.5.8 directory, but when I try to run the phpize command I get an error that says: Cannot find config.m4. Make sure that you run '/usr/bin/phpize' in the top level source directory of the module. I do however have the files acinclude.m4 and aclocal.m4 in this directory. I am not sure if they are related to the config.m4 that phpize is looking for.
I am not sure how to proceed. Maybe I should just cut my losses and install another PHP using Macports or Homebrew, but I'd really prefer to use the native PHP that came bundled with OS X. Can you help me figure out how to do this? It would really help me a lot, and help me understand better how PHP and extensions work. Thank you!
"I'd really prefer to use the native PHP that came bundled with OS X.
Can you help me figure out how to do this? It would really help me a
lot, and help me understand better how PHP and extensions work."
The PHP that came bundled with OSX isn't any more "Native" than any other version that you would install.
You don't have that directory because, IIRC, OSX doesn't ship with PHP source, just a compiled binary and apache module.
You can only run phpize on a php extension, which you can get in the PHP source download (including the mcrypt extension). What you downloaded is the C library (which you may also need to install) that the PHP extension will reference (you don't need to worry about how this happens).
If you want to just install that extension:
Download it
Extract and cd into
sudo phpize
sudo ./configure && sudo make && sudo make install
Add extension=mcrypt.so (or whatever is generated) to your php config / php.ini and restart apache
This sounds to me like a good opportunity to learn more about how your computer works. This is some documentation I wrote for myself a few years ago on how to do this:
http://www.calvinfroedge.com/common-php-compile-configuration-options/ (note that the formatting in the blog might not work if you paste it into terminal, for example –with-mysql should be --with-mysql)
Besides, you don't need to get rid of your PHP installation that came with OSX. You can download the PHP source to a brand new directory, compile it, backup the old binary, and either symlink the result of 'which php' to your new installation or add the binaries that get generated after you compile to your source.

Configure PHP and mysql connection under linux

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).

Categories