Deprecated mysql_ class in PHP v.7

378 views
Skip to first unread message

Abhishek Madhani

unread,
May 6, 2016, 8:34:12 AM5/6/16
to SQL Buddy
Hi,


I just installed PHP on Ubuntu 16.04 LTS and by default it install version 7. So I was trying to install your project, but after entering the login information it would load blank page and not connect. I checked the apache2 error logs, and it displayed the error message "Call to undefined function mysql_connect()" in "includes/class/Sql.php".

I replaced all mysql_* function with mysqli_*. While replacing I noticed somebody has mentioned that behaviour of mysql_result is slightly different than mysqli_result, "http://php.net/manual/en/class.mysqli-result.php#109782". I replaced.

After replacement, I was able to login, but it would not display any database, tables, users, or any server information.

Following more errors were occurred.

"PHP Warning:  mysqli_error() expects exactly 1 parameter" in "includes/class/Sql.php" on "line 152".

Regards


phpGuru

unread,
May 18, 2016, 9:53:54 AM5/18/16
to SQL Buddy
 Your best bet is to make some changes to Sql.php class to convert mysql to PDO. There's already PDO support. You'll need to change connect to us PDO, and then the method to pdo. You'll also need to fix getMetadata() which uses some mysql specific stuff. I took out the first section and used the second:

if ($this->conn) {

                        if ($this->adapter == "mysql") {

                                $schemaSql = $this->listDatabases();

                                if ($this->rowCount($schemaSql)) {

                                        while ($schema = $this->fetchArray($schemaSql)) {

                                                $output .= '{"name": "' . $schema[0] . '"';


                                                $this->selectDB($schema[0]);

                                                $tableSql = $this->listTables();


                                                if ($this->rowCount($tableSql)) {

                                                        $output .= ',"items": [';

                                                        while ($table = $this->fetchArray($tableSql)) {

                                                                $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table[0] . "`");

                                                                $rowCount = (int)($this->result($countSql, 0, "RowCount"));

                                                                $output .= '{"name":"' . $table[0] . '","rowcount":' . $rowCount . '},';

                                                        }


                                                        if (substr($output, -1) == ",")

                                                                $output = substr($output, 0, -1);


                                                        $output .= ']';

                                                }

                                                $output .= '},';

                                        }

                                        $output = substr($output, 0, -1);

                                }

                        } else if ($this->adapter == "sqlite") {



There's also a bug in rowCount for the pdo method:

        function rowCount($resultSet) {

                if (!$resultSet)

                        return false;

                if ($this->conn) {

                        if ($this->method == "pdo") {

                                return $resultSet->rowCount();

                                //return count($resultSet->fetchAll());

                        } else if ($this->method == "mysql") {

                                return @mysql_num_rows($resultSet);

                        } else if ($this->method == "sqlite") {

                                return @sqlite_num_rows($resultSet);

                        }

                }

        }


Carlos Martín Arnillas

unread,
Nov 26, 2016, 5:19:44 PM11/26/16
to SQL Buddy
PDO is a good option, as suggested by phpGuru.
I've did a little and quick fix yesterday, using mysqli (Function orientated, not the best, i know, but working)

You can download and check it at:

Ernst Jacob

unread,
Nov 27, 2017, 7:34:19 PM11/27/17
to SQL Buddy
This SqlBuddy Version handles MySqli and works at least up to PHP v.7.0.25 on my Servers.
Ernie

https://github.com/Frecuencio/sqlbuddy-php7
Reply all
Reply to author
Forward
0 new messages