php-src icon indicating copy to clipboard operation
php-src copied to clipboard

PHP Fatal error: Uncaught mysqli_sql_exception: Duplicate column name

Open conectarsistemas opened this issue 4 years ago • 3 comments

Description

The following code:

$cComando = 'ALTER TABLE T_ORGA ADD ORGA_VLR DECIMAL(18,8) NULL';
mysqli_query($link,$cComando)
if(mysqli_error($link)){
	echo '<br>Column exists';
}
<?php

Resulted in this output:

PHP Fatal error:  Uncaught mysqli_sql_exception: Duplicate column name
Stop execution do aplication.

But I expected this output instead:

Ignore the error and continue running aplication.

When I run the Alter Table in MYSQL, it returns Duplicate column name, but this shouldn't interrupt the process execution, just allow it to be treated normally as a standard error and continue executing the other commands.

This option to ignore the change if the column already exists is a database decision, not PHP's, so I believe there should be some command to ignore PHP Fatal error for these cases.

IMPORTANT : I have several databases and eventually some have some column missing, so I run the process on all databases.

PHP Version

PHP 8.1.4

Operating System

Windows 10

conectarsistemas avatar Mar 25 '22 13:03 conectarsistemas

Unfortunately, this is not a bug. I must close this report as invalid.

You can disable mysqli error reporting if you really wish so, or you can just catch the exception and handle it however you want. It's a standard PHP behaviour. Take a look at the documentation https://www.php.net/manual/en/mysqli-driver.report-mode.php

Here is a helpful guide written by one of PHP users: https://phpdelusions.net/mysqli/error_reporting

kamil-tekiela avatar Mar 25 '22 13:03 kamil-tekiela

Thanks.

conectarsistemas avatar Mar 25 '22 13:03 conectarsistemas

Thanks I'm testing my complete application in PHP 8.1.4, there are some problems and I'm adjusting. Another issue that I'm having a lot of difficulty solving is the SELECT result from the database. As various functions and other PHP processes are testing types, and the result of SELECT is always STRING, a comparisonof a numerical result, it is generating problems in case of NULL return, so I reported that it would be complicated to solve the issue.

Em sexta-feira, 25 de março de 2022 10:20:26 BRT, Kamil Tekiela ***@***.***> escreveu:  

Unfortunately, this is not a bug. I must close this report as invalid.

You can disable mysqli error reporting if you really wish so, or you can just catch the exception and handle it however you want. It's a standard PHP behaviour. Take a look at the documentation https://www.php.net/manual/en/mysqli-driver.report-mode.php

Here is a helpful guy written by one of PHP users: https://phpdelusions.net/mysqli/error_reporting

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

conectarsistemas avatar Mar 25 '22 13:03 conectarsistemas