Welcome Guest, Not a member yet? Register   Sign In
CI4 - > MySQLI Database -> query return result object even if error
#1

Good day

I did a test to see the Database objects and how the handle invalid queries. The logic is that if
the database query does not return a valid result that false is returned else the resource id is returned via the CI
Database framework

Database\BaseConnection->query
BaseConnection->simpleQuery
MySQLi\Connection->execute

the problem is that if one enteres a invalid query for example

select * from somewherethatdoesnotexist

then instead of it returned FALSE as one would expect for the error will be

mysqli_sql_exception: Table 'dominion_employees.somewhere' doesn't exist in /MySQLi/Connection.php:331

it returns (the mySQLI php lib that is) this object, that makes all code to handle invalid queries after it not work
as the object is a actual object now and not FALSE.


PHP Code:
(
    [connID] => mysqli Object
        
(
            [affected_rows] => -1
            
[client_info] => 5.5.66-MariaDB
            
[client_version] => 50566
            
[connect_errno] => 0
            
[connect_error] => 
            [errno] => 1146
            
[error] => Table 'somewhere' doesn't exist
            [error_list] => Array
                (
                    [0] => Array
                        (
                            [errno] => 1146
                            [sqlstate] => 42S02
                            [error] => Table '
somewhere' doesn't exist
                        
)

                )

            [field_count] => 0
            
[host_info] => Localhost via UNIX socket
            
[info] => 
            [insert_id] => 0
            
[server_info] => 5.6.41-84.1
            
[server_version] => 50641
            
[stat] => Uptime18262742  Threads6  Questions10888006908  Slow queries9126  Opens32322468  Flush tables1  Open tables16800  Queries per second avg596.186
            
[sqlstate] => 00000
            
[protocol_version] => 10
            
[thread_id] => 99238701
            
[warning_count] => 0
        
)

    [resultID] => 
    [resultArray] => Array
        (
        )

    [resultObject] => Array
        (
        )

    [customResultObject] => Array
        (
        )

    [currentRow] => 0
    
[numRows] => 
    [rowData] => 


I geuss one should in the mySQLI driver part check

PHP Code:
[errno] => 1146 

and if it is set, return false rather ?

Hope it helps

Johannes
Reply


Messages In This Thread
CI4 - > MySQLI Database -> query return result object even if error - by johannes - 07-11-2020, 04:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB