connect_errno) { die("Failed to connect to MySQL: ($mysqli->connect_errno) $mysqli->connect_error"); } return $mysqli; } /* ---------------------------------------------------------------------------- Run specified query and return result ---------------------------------------------------------------------------- */ function run_query($sql) { $db = db_connect(); $result = $db->query($sql); if (!$result) die('
Error: '.$db->error.'
SQL:
'.$sql.''); $db->close(); return $result; } /* ---------------------------------------------------------------------------- Runs the specified query and output success or error message as web page ---------------------------------------------------------------------------- */ function create_table($sql, $table_name) { $result = run_query($sql); if ($result === TRUE) $content = "Table $table_name was created successfully"; else $content = "Table $table_name was NOT created successfully"; make_basic_page("Table $table_name", $content); } /* ----------------------------------------------------------------------- Returns an HTML table from the specified table name ----------------------------------------------------------------------- */ function show_table($table_name) { $cols = run_query("SHOW FULL COLUMNS FROM $table_name"); $rows = run_query("SELECT * FROM $table_name"); if ($cols) { while($col = $cols->fetch_assoc()) { $ths .= '
'.$table_name.'
'.$table_name.'