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 .= ''.$col['Field']. ''; } } if ($rows) { while($row = $rows->fetch_assoc()) { $tds .= ''; foreach($row as $value) $tds .= ''.$value.''; $tds .= ''; } } $out = '

Table Data: '.$table_name.'

'; $out .= ' '.$ths.' '.$tds.'
'; return $out; } /* ----------------------------------------------------------------------- Returns all the column information from the specified table name ----------------------------------------------------------------------- */ function show_table_columns($table_name) { $cols = run_query("SHOW FULL COLUMNS FROM $table_name"); $out = '

Column Info: '.$table_name.'

'; $x = 0; while($col = $cols->fetch_assoc()) { $out .= '

Field '.++$x.'

'; } return $out; } ?>