Call to undefined function mysql_connect()

Tried the update. I got an error:

[Mon Feb 01 20:13:40.743747 2016] [:error] [pid nr] [client ip] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /path/to/invoiceplane-1.4.5/application/modules/setup/libraries/Lib_mysql.php

Note I have “mysqli” defined in my database.php file. This worked correctly in version 1.4.4 but now seems to fail on the mysql_connect function upon update. (setup step “database configuration”)

Could you please compare the contents of your Lib_mysql.php file and this file. If they are the same this error should not pop up as the function is present in the library file…

Thanks for your quick response. It’s identical.

I tried editing the Lib_mysql file and I changed this line

if (@mysql_connect($server, $username, $password)) {

to this

if (@mysqli_connect($server, $username, $password, “my-db-name”)) {

The error now went away but it failed on the next mysql command that I didn’t transform to its mysqli equivalent function.

So my guess is that somehow the database.php parameter db_driver doesn’t get taken into account.

Thats very weird.
I was able to upgrade an existing installation as well as running a clean setup without any problems.

Extra info:

mysql version & php version

mysql Ver 15.1 Distrib 10.1.10-MariaDB, for Linux (x86_64) using readline 5.1
PHP 7.0.2 (cli) (built: Jan 6 2016 11:50:59) ( NTS )

I think that’s the problem.
I tested most of InvoicePlane while running PHP 7 but I would not recommend running it in production yet.

Is there a way to force invoiceplane to use mysqli functions for everything? Is there more to configure except the database.php file?

The database.php file and its contents are not relevant for tis problem, the architecture of the setup uses this standalone library (lib_mysql) to check the database connectivity.
Which is quite bad but I will try to solve this as fast as possible.


I noticed no problems with php 7.0.2 in the previous version, so the software itself works fine with php7. Still the setup is the problem. I managed to hack it in an ugly fashion and managed to get through the setup procedure successfully. As mentioned, I changed all occurrences of mysql_ functions to their mysqli_ equivalents. A short overview of Lib_mysql:

add a public link variable to hold the connection (ugly, could be handled nicer I guess)

public $link;

The connect function (also ugly - notice the extra database parameter):

$this->link = mysqli_connect($server, $username, $password, $database);
if (@mysqli_connect($server, $username, $password, $database)) {

The select_db function (referring to the link that holds the connection):

if (@mysqli_select_db($this->link, $database)) {

Then the query function:

    $result = mysqli_query($sql);
    return mysqli_fetch_object($result);

Small change required in /application/modules/setup/controllers/setup.php (pass the database param)

$can_connect = $this->lib_mysql->connect($db[‘hostname’], $db[‘username’], $db[‘password’]);


$can_connect = $this->lib_mysql->connect($db[‘hostname’], $db[‘username’], $db[‘password’], $db[‘database’]);

This should do the trick if you desperately want to upgrade. Otherwise, wait until Kovah had the time to change the setup library more professionaly.

1 Like