How can one efficiently handle the addition of new columns to a database table in PHP without manually updating scripts?
When adding new columns to a database table in PHP, it is important to automate the process to avoid manually updating scripts each time. One efficient way to handle this is by using a migration tool like Phinx, which allows you to define database changes in code and easily apply them to your database.
use Phinx\Migration\AbstractMigration;
class AddNewColumnsToTable extends AbstractMigration
{
public function change()
{
$table = $this->table('your_table_name');
$table->addColumn('new_column1', 'string', ['null' => true])
->addColumn('new_column2', 'integer', ['default' => 0])
->update();
}
}