# apache can't connect to mysql



## Lido (Sep 12, 2012)

I'm getting the following in /var/log/httpd-error.log:

```
PHP Fatal error:  Call to undefined function mysql_connect() in /...
```

mysql seems to be installed (from php_info()):

```
mysqlnd
mysqlnd	enabled
Version 	mysqlnd 5.0.8-dev - 20102224 - $Id: 65fe78e70ce53d27a6cd578597722950e490b0d0 $
Compression 	not supported
SSL 	supported
Command buffer size 	4096
Read buffer size 	32768
Read timeout 	31536000
Collecting statistics 	Yes
Collecting memory statistics 	No
Tracing 	n/a
```


pkg_info|grep php|grep mysql:

```
# pkg_info | grep php | grep mysql
php53-mysql-5.3.15  The mysql shared extension for php
```


----------



## mamalos (Sep 12, 2012)

You should install the PHP module databases/php5-mysql, otherwise it won't work.


----------



## Lido (Sep 12, 2012)

mamalos said:
			
		

> You should install the PHP module databases/php5-mysql, otherwise it won't work.



It's installed:


```
#pkg_info
...
php53-mysql-5.3.15  The mysql shared extension for php
...
```


----------



## chatwizrd (Sep 12, 2012)

Make sure its loaded in extensions.ini for php to be able to use it.

Try the following command it should tell you where extensions.ini is located.

`# php --ini`

You should extension=mysql.so on one line.


----------



## Lido (Sep 12, 2012)

```
# php --ini
Configuration File (php.ini) Path: /usr/local/etc
Loaded Configuration File:         (none)
Scan for additional .ini files in: /usr/local/etc/php
Additional .ini files parsed:      /usr/local/etc/php/extensions.ini,
/usr/local/etc/php/php.ini
```


----------



## mamalos (Sep 13, 2012)

As *chatwizrd* suggested, you should open /usr/local/etc/php.ini and see if you find an uncommented line reading:


```
extension=mysql.so
```

<offtopic>@SirDice, which is the icon for port-tags?</offtopic>


----------



## SirDice (Sep 13, 2012)

mamalos said:
			
		

> <offtopic>@SirDice, which is the icon for port-tags?</offtopic>


There isn't any.

http://forums.freebsd.org/misc.php?do=bbcode#port


----------



## usdmatt (Sep 13, 2012)

Just a quick note that when using the port, the extensions are added to /usr/local/etc/php/extensions.ini so you should look there for the mysql.so entry, not the php.ini file. (Of course if it's already in there, it could suggest that the problem is that php is not reading this file, however your --ini output suggests php is configured to look there)

Going back to the original post, I don't think the mysqlnd entry in your php_info output shown confirms that these functions will be available. mysql_connect() is provided by the mysql extension, not mysqlnd. You should see something like the following in php -i output if the correct extension is loaded (in addition to the mysqlnd section):


```
mysql

MySQL Support => enabled
Active Persistent Links => 0
Active Links => 0
Client API version => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $
```


----------



## Lido (Sep 13, 2012)

Thanks. Actually rebooting solved the issue. I'm guessing that restarting apache might have also done the trick, but I'm not sure. This all happened after a port update that included php, mysql and apache22 threaded.


```
mysql

MySQL Support => enabled
Active Persistent Links => 0
Active Links => 0
Client API version => mysqlnd 5.0.8-dev - 20102224
```


----------

