MySql does not update column

I am trying to add two columns to a database when running a script. The problem is when the second column is created it is of the type int

when I really want it varchar2

.

My request:

$query1 = "ALTER TABLE `keyword_table` ADD `".$currentWeek."` INT NOT NULL AFTER `".$previousWeek."_url`";
$query2 = "ALTER TABLE `keyword_table` ADD `".$currentWeek."_url` VARCHAR2(100) NOT NULL AFTER `".$currentWeek."`"

      

Query when variables are placed:

ALTER TABLE `keyword_table` ADD `07_07_2015` INT NOT NULL AFTER `01_07_2015_url`
ALTER TABLE `keyword_table` ADD `07_07_2015_url` VARCHAR2(100) NOT NULL AFTER `07_07_2015`

      

These queries are how I wanted them, however, when the second query is executed, it creates the column where I want, but as int

not a varchar2

. I checked the syntax, I went to PhpMyAdmin and looked at the syntax it uses when inserting a column and it is the same as above.

Any ideas why it doesn't make the column correct?

edits

I ran the code like this:

$query = "ALTER TABLE `keyword_table` ADD `".$currentWeek."` INT NOT NULL AFTER `".$previousWeek."_url`";
mysqli_query($conn, $query);
echo $query.'<br>';
$query = "ALTER TABLE `keyword_table` ADD `".$currentWeek."_url` VARCHAR2(100) NOT NULL AFTER `".$currentWeek."`";
mysqli_query($conn, $query);
echo $query.'<br>';

      

+3


source to share


2 answers


VARCHAR2

is an Oracle specific vendor. If you are not using Oracle you should use VARCHAR(100)

.

For the most part, the difference is small.

The difference is ...



VARCHAR(100)

- allocated memory 100 regardless of whether there are only 50 characters.

VARCHAR2(100)

- the allocated memory is equal only to the number of characters entered in the field.

Happy coding!

+2


source


There is no datatype in mysql like VARCHAR2. Use VARCHAR instead.



For a list of data types supported by mysql see here: https://dev.mysql.com/doc/refman/5.0/en/data-types.html

0


source







All Articles