Skip to content

PHP Fatal error: Uncaught mysqli_sql_exception: Duplicate column name #8249

@conectarsistemas

Description

@conectarsistemas

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions