Unable to enable debug_kit5 on cakephp5

I created a skeleton cakephp5 project with the following command on a FreeBSD based shared hosting and got a welcome page of CakePHP5 with green status of DB connection.

composer create-project --prefer-dist cakephp/app:~5.0 sample

After this, when I enabled debug_kit using the follwing method, an error occurred.
I wrote the following in config/bootstrap.php.

// Add the following inside the block.
if (Configure::read('debug')) {
Configure::write('DebugKit.forceEnable', true);

The DB file tmp/debug_kit.sqlite exists. Permission is 644. Even if I change it to 666, the same error occurs.

Error message displayed in browser:

Warning (2) : Undefined array key "origin" [in /home/user/example.com/sample/vendor/cakephp/cakephp/src/Database/Schema/SqliteSchemaDialect.php, line 333]
Warning (2) : Undefined array key "origin" [in /home/user/example.com/sample/vendor/cakephp/cakephp/src/Database/Schema/SqliteSchemaDialect.php, line 348]
Warning (512) : Unable to emit headers. Headers sent in file=/home/user/example.com/sample/vendor/cakephp/cakephp/src/Error/Renderer/HtmlErrorRenderer.php line=37 [in /home/user/example.com/sample/vendor/cakephp/cakephp/src/Http/ResponseEmitter.php, line 65]
  • Errors related to HTTP headers are omitted.
SQLSTATE[HY000]: General error: 1 near "(": syntax error

Caused by
SQLSTATE[HY000]: General error: 1 near "(": syntax error
CORE/src/Database/Driver.php at line 353(edit)
353 : $statement = $this->getPdo()->prepare($query instanceof Query ? $query->sql() : $query);

By adding the following line just before this line,
print_r($query instanceof Query ? $query->sql() : $query);exit();
the following was displayed.
SELECT name FROM sqlite_master WHERE (type="table" OR type="view") AND name != "sqlite_sequence" ORDER BY name

On the shell, when I executed the above SQL statement on the sqlite3 using debug_kit.sqlite the following was displayed:


What could be the problem?"
CakePHP 5.0.2
sqlite3 3.41.2
PHP 8.1

Get rid of the exit in your test code. You’re showing the very first query being executed, but maybe that’s not the one that’s causing the error. A typical request may involve quite a number of queries.

I am unable to reproduce your problem.
Just created a fresh cake5 app and the debug kit opens without a problem on http://localhost:8765

Thank you for the tip.
I changed the debug statement as follows.

print_r($query instanceof Query ? $query->sql() : $query);print_r(';<br>');


SELECT name FROM sqlite_master WHERE (type="table" OR type="view") AND name != "sqlite_sequence" ORDER BY name;
PRAGMA table_info("requests");
PRAGMA index_list("requests");
Warning (2) : Undefined array key "origin" [in /home/user/example.com/sample/vendor/cakephp/cakephp/src/Database/Schema/SqliteSchemaDialect.php, line 333]
PRAGMA index_info("sqlite_autoindex_requests_1");
Warning (2) : Undefined array key "origin" [in /home/user/example.com/sample/vendor/cakephp/cakephp/src/Database/Schema/SqliteSchemaDialect.php, line 348]

I get the same error when starting a new project.
There may be a problem with the execution environment.
However, CakePHP4 is running in the same environment.
I will try changing the environment.

I’ve researched this issue further. I noticed that it works fine in my local environment, but not in my hosting environment.

Local Enviroment
Ubuntu 22.04.3 LTS on WSL2
PHP Version 8.1.25
SQLite Library 3.37.2
composer create-project --prefer-dist cakephp/app:~5.0 sample 直後
cd sample
bin/cake server

■ Next, we looked at the part that checks the connection in the default template home.php on the hosting environment that causes the error.
When I output the debug, it was a connection error.

(on the hosting environment)

■ Next, I added in bootstrap.php,

Configure::write(‘DebugKit.forceEnable’, true);

In this case, an SQL error will occur as shown in the first image of this thread.

■ Next, since there was a connection error on home.php, I added the following to app_local.php.

// After creating the database debug_kit.
'debug_kit' => [
     'className' => 'Cake\Database\Connection',
     'driver' => 'Cake\Database\Driver\Mysql',
     'persistent' => false,
     'host' => 'localhost',
     'username' => 'xxxxxx', // Your DB username here
     'password' => 'yyyyyy', // Your DB password here
     'database' => 'cakephp5debug',

The sign is now green.

I haven’t tried it with any other hosting, but I’m tired so I think this is fine.

Good to see that you resolved the issue by switching to a MySQL database and driver.

For future reference, the issue appears to be CakePHP/Debug Kit using the SQLite driver for a MySQL database. The database connection manager tries to reflect foreign keys by firing off a request containing “pragma_foreign_key_list” - something that MySQL doesn’t support. It’s not clear to me why Debug Kit is trying to use the MySQL database bundled on OP and I’s servers, perhaps a lack of PDO_SQLITE? But setting the debug_kit database to something else apart from SQLite will fix the issue.

This problem has been solved!
It was because the version of SQLite on the hosting server I was using was old.
Recently, SQLite on the hosting server was updated from 3.7.x to 3.26.x.
I installed CakePHP5 again, and DebugKit worked.