Thk-analytics と php8.4 の不具合解消

Thk-analyticsは、無料で使えるアクセス解析ツールです。非常に優秀なんですが、2018年以降開発が止まっており最新のLinuxに対応していません。Debian Linux Trixie でも動かなくなっています。そこで、とりあえず最新のLinuxでエラーが出ないように修正いたしました。

検証バージョン:
Debain Linux kernel: 6.12.43+deb13-amd64
PHP: 8.4.11 (cli) (built: Aug 3 2025 07:32:21) (NTS)
Mysql: mysql from 11.8.3-MariaDB, client 15.2

原因:
1.PHPのmysqli_connect, mysqli_query 等の返り値が変更となり、成功した場合 null だったのが true になった。
2.$exception->getNativeError() の手続きが無くなった。

以上を修正した patch が以下の通り。

ダウンロードはこちらから。ブラウザーの保存機能で保存してください。
———————————————————-
diff -uprN thk-analytics-124.orig/_core/system/Thk.php thk-analytics-124/_core/system/Thk.php
— thk-analytics-124.orig/_core/system/Thk.php 2017-05-24 04:11:22.000000000 +0900
+++ thk-analytics-124/_core/system/Thk.php 2025-11-11 08:59:12.465378969 +0900
@@ -119,7 +119,7 @@ class Thk {
restore_error_handler();
}
catch ( Exception $exception ) {
– if( ( $exception->getNativeError() ) || ( $this->_controller == ThkConfig::ERR_CTRL_NAME && $this->_action == ThkConfig::ERR_ACTION_NAME ) ) {
+ if( ( $this->_controller == ThkConfig::ERR_CTRL_NAME && $this->_action == ThkConfig::ERR_ACTION_NAME ) ) {
$this->_showError( $exception, $this->_request, $this->_session, $this->_message, $result );
restore_error_handler();
}
diff -uprN thk-analytics-124.orig/_core/system/ThkModel.php thk-analytics-124/_core/system/ThkModel.php
— thk-analytics-124.orig/_core/system/ThkModel.php 2018-03-24 19:20:52.000000000 +0900
+++ thk-analytics-124/_core/system/ThkModel.php 2025-11-12 21:30:14.007950073 +0900
@@ -590,12 +590,14 @@ abstract class ThkModel {
* @return resource $rs Resource
*/
protected final function query( $query ) {
+ try {
$rs = mysqli_query( $this->_conn, $query );
– if( !$rs ) {
– $errno = mysqli_errno( $this->_conn );
+ }
+ catch( Exception $ex ) {
+ $errno = $ex->getCode();
switch( $errno ) {
case self::TABLE_NOTFOUND_ERR_CODE:
– if( !$this->_noCreate ) {
+ if( $this->_noCreate == null ) {
$this->createTable();
$rs = mysqli_query( $this->_conn, $query );
}
@@ -619,7 +621,7 @@ abstract class ThkModel {
protected final function execute( $sql ) {
$this->_begin();
$rs = mysqli_query( $this->_conn, $sql );
– if( !$rs ) {
+ if( $rs == false ) {
$this->_rollback();
$errno = mysqli_errno( $this->_conn );
throw new ThkException( $sql . ‘:’ . mysqli_error( $this->_conn ), $errno, true );
@@ -699,7 +701,7 @@ abstract class ThkModel {
* dbDisconnect
*/
private function _dbDisconnect() {
– if( $this->_conn !== null ) mysqli_close( $this->_conn );
+ if( $this->_conn == false ) mysqli_close( $this->_conn );
25,1 Top
———————————————————


コメント

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です