Welcome Guest, Not a member yet? Register   Sign In
adding field at a table
#1

[eluser]aktosci[/eluser]
Hello,

I am creating the automatic install of my database

Creation of the table : OK

but when my database is changing , I have to add fields

1st method : CI
Code:
$fields = array('newfield' => array('type' => 'TEXT'));
$this->dbforge->add_column('table', $fields);
--> This methode send me an error when the field exists


A Database Error Occurred

Code:
Error Number: 1060

Duplicate column name 'newfield'

ALTER TABLE `table` ADD `newfield` TEXT

2nd method : classic php
Code:
$strsql = "ALTER TABLE `aaa` ADD `gract_visible` VARCHAR( 1 ) ;";
mysql_query($strsql);
this method does not send me an error when the field exist and I want that !

-->Question : do you have a solution in CI adding fiedl ( I don't know if this new field exist of not )

Second method what is the advantade of using the CI method ?
#2

[eluser]TheFuzzy0ne[/eluser]
It would be wise to check whether or not the field exists in the database before altering it.

The advantage of the first method over the first, is that your errors are handled with no effort from you.




Theme © iAndrew 2016 - Forum software by © MyBB