Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active August 7, 2019 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/5554190d0ccc5033284736a2b6f6cd57 to your computer and use it in GitHub Desktop.
Save parzibyte/5554190d0ccc5033284736a2b6f6cd57 to your computer and use it in GitHub Desktop.
<?php
function obtenerColumnasDeUnaTabla($host, $usuario, $pass, $nombreDeLaBaseDeDatos, $nombreDeLaTabla)
{
try {
$base_de_datos = new PDO("mysql:host=$host;dbname=$nombreDeLaBaseDeDatos",
$usuario, $pass);
} catch (Exception $e) {
echo "Ocurrió algo con la base de datos: " . $e->getMessage();
}
return $base_de_datos
->query("SELECT COLUMN_NAME AS columna, COLUMN_TYPE AS tipo
FROM information_schema.columns WHERE
table_schema = '$nombreDeLaBaseDeDatos'
AND table_name = '$nombreDeLaTabla'")
->fetchAll(PDO::FETCH_OBJ);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment