Error when using the Database class in PHP 7

Y’ello
So I tried to move one of the sites over to php7, which is fantastic, but I’m getting a 500 error when I’m running a route that calls from a DB

This is the configure command

'./configure' '--prefix=/opt/php-7.0' '--with-libdir=lib64' '--with-config-file-path=/opt/php-7.0/etc' '--with-config-file-scan-dir=/opt/php-7.0/etc/conf.d' '--enable-cli' '--enable-calendar' '--enable-ctype' '--enable-dom=shared' '--enable-exif' '--enable-filter' '--enable-ftp=shared' '--enable-hash' '--enable-posix=shared' '--enable-opcache=shared' '--enable-session' '--enable-simplexml' '--enable-sockets=shared' '--enable-soap=shared' '--enable-json' '--enable-inline-optimization' '--enable-tokenizer' '--enable-xml=shared' '--enable-mbregex' '--enable-mbstring=shared' '--enable-libxml=shared' '--enable-dba=shared' '--enable-bcmath=shared' '--enable-gd-native-ttf' '--enable-pdo=shared' '--enable-xmlreader=shared' '--enable-xmlwriter=shared' '--enable-zip=shared' '--enable-mysqlnd=shared' '--enable-intl=shared' '--with-libxml-dir=/usr' '--with-zlib=/usr' '--with-bz2=/usr' '--with-curl=/opt/hostlibs/curl' '--with-pcre-regex=/opt/hostlibs/pcre-8.38' '--with-gd=shared' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-freetype-dir=/usr' '--with-gettext=/usr' '--with-gmp=/usr' '--with-mcrypt=shared,/usr' '--with-mhash=shared,/usr' '--with-tidy=shared,/usr' '--with-mysqli=shared,/usr/bin/mysql_config' '--with-sqlite3=shared' '--with-pdo-sqlite=shared,/usr' '--with-pdo-mysql=shared,/usr' '--with-libexpat-dir=/usr' '--with-xmlrpc=shared' '--with-xsl=shared,/usr' '--with-openssl=/usr' '--with-imap=shared' '--with-imap-ssl' '--with-pear=/opt/php-7.0/pear' '--with-iconv' '--with-kerberos'

and the route

array(
    "pattern" => "out/(:any)/title",
    "method" => "GET",
    "action" => function($call) {
        $db = new Database(array(
            "type"      =>  "mysql",
            "host"      =>  "localhost",
            "database"  =>  "gsponsor",
            "user"      =>  "root",
            "password"  =>  "root"
        ));

        $companies = $db->table("companies");
        $company = $companies->where("company_slug", "=", $call)->first();
        return response::json(array(
            "title" => $company->company_name()
        ));
    }
),

Without an error message that’s difficult to say. Is there any error message in the Apache error log?

Unfortunately there aren’t any error messages, I’ve turned on all levels of error reporting in PHP, Nginx and MariaDB, but there aren’t anything logging.

If I downgrade to php 5.6, it is working again, and it has this configure command

'./configure' '--prefix=/opt/php-5.6' '--with-libdir=lib64' '--with-config-file-path=/opt/php-5.6/etc' '--with-config-file-scan-dir=/opt/php-5.6/etc/conf.d' '--enable-cli' '--enable-calendar' '--enable-ctype' '--enable-dom=shared' '--enable-exif' '--enable-filter' '--enable-ftp=shared' '--enable-hash' '--enable-posix=shared' '--enable-opcache=shared' '--enable-session' '--enable-simplexml' '--enable-sockets=shared' '--enable-soap=shared' '--enable-json' '--enable-inline-optimization' '--enable-tokenizer' '--enable-xml=shared' '--enable-mbregex' '--enable-mbstring=shared' '--enable-libxml=shared' '--enable-dba=shared' '--enable-bcmath=shared' '--enable-gd-native-ttf' '--enable-pdo=shared' '--enable-xmlreader=shared' '--enable-xmlwriter=shared' '--enable-zip=shared' '--enable-mysqlnd=shared' '--enable-intl=shared' '--with-libxml-dir=/usr' '--with-zlib=/usr' '--with-bz2=/usr' '--with-curl=/opt/hostlibs/curl' '--with-pcre-regex=/opt/hostlibs/pcre-8.38' '--with-gd=shared' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-freetype-dir=/usr' '--with-gettext=/usr' '--with-gmp=/usr' '--with-mcrypt=shared,/usr' '--with-mhash=shared,/usr' '--with-mysql=shared,/usr' '--with-tidy=shared,/usr' '--with-mysqli=shared,/usr/bin/mysql_config' '--with-sqlite3=shared' '--with-pdo-sqlite=shared,/usr' '--with-pdo-mysql=shared,/usr' '--with-libexpat-dir=/usr' '--with-xmlrpc=shared' '--with-xsl=shared,/usr' '--with-openssl=/usr' '--with-imap=shared' '--with-imap-ssl' '--with-pear=/opt/php-5.6/pear' '--with-iconv' '--with-kerberos'

I’ve hired an server technician to go over it, he also checked that all levels of reporting had been enabled, so if there’s an error, it should be logged. But it isn’t. And he could not either find the error.

I tried to enable $fail = true in kirby/toolkit/database.php for throwing messages, still nothing. Are there any other variables I can change to true for more reporting?

Kirby provides the debug option (c::set('debug', true)), but that only sets the PHP error reporting, so it shouldn’t add more error reporting in your case if you already enabled everything.

Does the HTTP 500 error still occur if you comment out the code inside the route (comment out everything and if that works, only comment out the last two lines with the DB query)?
Do you get a blank page with HTTP 500 status code or does Nginx display an HTML error page that says “Internal Server Error”?

Enabled

c::set("debug", true)

And now it throws me this error


Notice: Array to string conversion in /home/u769777553/public_html/kirby/toolkit/lib/database.php on line 318

Notice: Undefined property: PDOStatement::$Array in /home/u769777553/public_html/kirby/toolkit/lib/database.php on line 318

Fatal error: Uncaught Error: Function name must be a string in /home/u769777553/public_html/kirby/toolkit/lib/database.php:318 Stack trace: #0 /home/u769777553/public_html/kirby/toolkit/lib/database/query.php(653): Database->query('SELECT * FROM c...', Array, Array)
#1 /home/u769777553/public_html/kirby/toolkit/lib/database/query.php(691): Database\Query->query('SELECT * FROM c...', Array)
#2 /home/u769777553/public_html/site/config/config.php(80): Database\Query->first()
#3 /home/u769777553/public_html/kirby/toolkit/helpers.php(270): Kirby->{closure}('aventura-amazon...')
#4 /home/u769777553/public_html/kirby/kirby.php(746): call(Object(Closure), Array)
#5 /home/u769777553/public_html/index.php(16): Kirby->launch()
#6 {main} thrown in /home/u769777553/public_html/kirby/toolkit/lib/database.php on line 318

If I disable the two lines with DB query, it directs me to the home page, as wanted.

Thanks, that helps. I will look into this later.

Which Kirby version are you using? I have fixed this exact bug in December before the PHP 7 release and it is included in Kirby 2.2.3. Older Kirby versions are not compatible with PHP 7.

2 Likes

I’m using 2.2.2 for this project, must have forgotten to update to latest version.
I’m going to update to 2.2.3 and let you know if it works

Yep, it is working. Good to know.
I’ll make sure I update all projects to 2.2.3 to avoid this problem again

1 Like