Topic: Error Handler not working for php 8.2

When we even turn on the go_debug 2. that doesnt get the mysql errors like 1062 duplicate entry, 1054 column not found errors are not showing the query which get this error.  But in php 8.0 it works fine.

We need to update the error handler or fix it work based on php 8.2

Subscription service based on FA
HRM CRM POS batch Themes

Re: Error Handler not working for php 8.2

A note page in the wiki would be good to know the extent of PHP version compatibility for each release.

Re: Error Handler not working for php 8.2

For this issue. We should update on our FA program. I guess not on wiki. People needs to move to next php versions. So it's important to fix in core of FA

Subscription service based on FA
HRM CRM POS batch Themes

Re: Error Handler not working for php 8.2

Let us freeze the PHP version for this FA version.
People should not keep updating PHP version frequently.

Re: Error Handler not working for php 8.2

I am feeling this change will get it worked.

@joe consider checking it on php 8.1 and 8.2 with existing code and also my new function of db_query



function db_query($sql, $err_msg=null)
{
    global $db, $SysPrefs, $sql_queries, $Ajax,    $db_connections, $db_last_inserted_id;

    // set current db prefix
    $comp = isset($_SESSION["wa_current_user"]->cur_con) ? $_SESSION["wa_current_user"]->cur_con : 0;
    $cur_prefix = @$db_connections[$comp]['tbpref'];
    $sql = str_replace(TB_PREF, $cur_prefix, $sql);

    if ($SysPrefs->show_sql)
    {
        $Ajax->activate('footer_debug');
        $sql_queries .= "<pre>$sql</pre>\n<hr>";
    }

    db_profile(); // mysql profiling

    $retry = MAX_DEADLOCK_RETRY;
 try { //kvvaradha added try and catch 
    do {
        $result = mysqli_query($db, $sql);
        if (mysqli_errno($db) == 1213)    { // deadlock detected
            sleep(1); $retry--;
        } else {
            throw new mysqli_sql_exception("Deadlock detected: $sql", 1062); //kvvaradha added to through the error in an exception and handle it on catch 
            $retry = 0;
        }
    } while ($retry);

    db_profile($sql);

    if($SysPrefs->sql_trail) {
        $db_last_inserted_id = mysqli_insert_id($db);    // preserve in case trail insert is done
        if ($SysPrefs->select_trail || (strstr($sql, 'SELECT') === false)) {
            mysqli_query($db, "INSERT INTO ".$cur_prefix."sql_trail
                (`sql`, `result`, `msg`)
                VALUES(".db_escape($sql).",".($result ? 1 : 0).",
                ".db_escape($err_msg).")");
        }
    }
 } catch (mysqli_sql_exception $e) {. //kvvaradha added catch 
        $error_msg = $e->getMessage();
        $error_code = $e->getCode();
    if ($err_msg != null || $SysPrefs->go_debug) {
        $exit = $err_msg != null;
        if (function_exists('xdebug_call_file'))
            $err_msg = '<br>At file '.xdebug_call_file().':'.xdebug_call_line().':<br>'.$err_msg;
        check_db_error($err_msg, $sql, $exit);
    }
 throw $e; // rethrow the exception after handling
    }
    return $result;
}

I added error handling with try catch inorder to get the detailed query during the time of mysqli_sql_exception.

Subscription service based on FA
HRM CRM POS batch Themes

Re: Error Handler not working for php 8.2

With this code

 srand ((double) microtime( )*1000000); 

we are getting error like this in sometime Implicit conversion from float 517375.00000000006. due to the double in it. so lets convert this into int.

 srand ((int) microtime( )*1000000); 

 

make this change on items.php to take effect.

Subscription service based on FA
HRM CRM POS batch Themes

Re: Error Handler not working for php 8.2

apmuthu wrote:

Let us freeze the PHP version for this FA version.
People should not keep updating PHP version frequently.

I totally agree, but from personal experience updating is driven by the hosting companies; changing version without notice and often to obscure version numbers; then in some cases, not allowing previous versions to be used. Yes you get what you pay for, but initially most users will factor cost when choosing hosting.

I have no answers, but I would very much like to see a solution to this.

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

Re: Error Handler not working for php 8.2

apmuthu wrote:

A note page in the wiki would be good to know the extent of PHP version compatibility for each release.

A sticky message in its own forum would also work

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

9 (edited by kvvaradha 03/27/2024 05:01:33 am)

Re: Error Handler not working for php 8.2

We have another required parameter after the optional parameter.

on profit_loss.php

function display_type ($type, $typename, $from, $to, $begin, $end, $compare, $convert,
    $dimension=0, $dimension2=0, $drilldown, $path_to_root)

here $drilldown can be put default value as 0

And $path_to_root can be declared as global variable inside the display_type

function display_type ($type, $typename, $from, $to, $begin, $end, $compare, $convert,
    $dimension=0, $dimension2=0, $drilldown=0) {
        global $path_to_root;

this will work there

Subscription service based on FA
HRM CRM POS batch Themes

Re: Error Handler not working for php 8.2

The function display_type() is defined separately in each of these reports in the reporting folder:

rep701.php
rep705.php
rep706.php
rep707.php
rep708.php

where the said $path_to_root is not used.

The $path_to_root variable is defined as global in gl/inquiry/balance_sheet.php as a standalone function.

The only place where the function needs to be changed is in gl/inquiry/profit_loss.php. It is defined in line 57 and is used in lines 108, 264 and 320.

In each case, the locally defined functions are not used outside the specific file.

@joe: kindly make the changes in gl/inquiry/profit_loss.php.

Those files in extensions who "include" this file should be aware of such a change and make amends if and when this is committed.

@joe: can commit changes to this file as needed.

Re: Error Handler not working for php 8.2

Will check on this today.

Joe

Re: Error Handler not working for php 8.2

Fixed both errors. The one in gl/inquiry/profit_loss.php and the one in inventory/manage/items.php.

Pushed to stable repo.

/Joe