Skip to content

Instantly share code, notes, and snippets.

@mweppler
Created November 21, 2012 16:09
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 mweppler/4125711 to your computer and use it in GitHub Desktop.
Save mweppler/4125711 to your computer and use it in GitHub Desktop.
<?php
$field = "field";
$hasField = false;
$table = "table";
$connect = @mysql_connect("host","username","password");
if (!$connect) echo "Server error: CONN";
$select_db = mysql_select_db("database");
if (!$select_db) echo "Server error: DB";
$result = mysql_query("SHOW COLUMNS FROM $table");
while ($row = mysql_fetch_array($result))
if ($row["Field"] == $field) $hasField = true;
mysql_free_result($result);
echo "Does $table table have $field field?: ".($hasField) ? "YES\n" : "NO\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment