Change type of all table fields

1

Can you change all fields in my table to VARCHAR ? I have a table with a lot of fields and I wanted all fields to be automatically changed to type VARCHAR

    
asked by anonymous 13.02.2016 / 20:07

1 answer

1

Make a script in PHP

$tabela = "nomedatabelaparamodificar"

$sql = mysqli_query($conn, "SHOW COLUMNS FROM $tabela");

while ($lista = mysqli_fetch_array($sql)){

$array[] = $lista[0];


}


foreach ($array as $valor){
	
	
	mysql_query($conn, "ALTER TABLE $tabela MODIFY $valor VARCHAR(50)");
	
}

Try this!

    
13.02.2016 / 20:31