I am doing well with mySql, but when it comes to some quirks I am struck.
This is something I used for years successfully
$sql = "ALTER TABLE " . $Tablu . " ADD " . $Colu . " varchar(" . intVal($Siza) .")";
What I want now is just add a DEFAULT value for the new column I am adding. Please provide a syntax WITH THE EXISTING STRUCTURE of the query. That is with THE QUOTES
I am trying this
$sql = "ALTER TABLE " . $Tablu . " ADD " . $Colu . " varchar(" . intVal($Siza) .") DEFAULT ('" . $defa . "')";
But it is NOT working
I CANNOT understand the without-quotes-mysql game at all.
Thanks in advance
you query is ok .. you just need to remove those brackets () around $defa.. like this-
$sql = "ALTER TABLE " . $Tablu . " ADD " . $Colu . " varchar(" . intVal($Siza) .") DEFAULT '" . $defa . "'";
This might be the correct way to do it.
$sql = "ALTER TABLE " . $Tablu . " ADD " . $Colu . " varchar(" . intVal($Siza) ." DEFAULT 'default_value')";
You can set the default value in the quotes itself using
SET DEFAULT 'value'
OR SET DEFAULT NULL
Your query will be like
$sql = "ALTER TABLE " . $Tablu . " ADD " . $Colu . " varchar(" . intVal($Siza) .")" . " SET DEFAULT " . $defa;