Change type of all table fields

Asked

Viewed 122 times

1

You can change all fields in my table to VARCHAR? I have a table with plenty of fields and I wanted all fields to be automatically changed to type VARCHAR

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!

  • Thanks for the solution =)

  • Sorry, there was a confusing...the script I made changes the tables......

  • 1

    Okay, I corrected and made some improvements....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.