Now it’s time to get into the meat and potatoes of this thing. We need to break into our else block and construct the code that should be executed in the event that POST data is found. <?php } else {
$mysql_db = $_REQUEST['d']; $mysql_user = $_REQUEST['u']; $mysql_pass = $_REQUEST['p']; $table_prefix = $_REQUEST['n']; We’re going to begin by grabbing the POST data set back by our form and pushing that into a few variables for later use. // Open MySQL link $link = mysql_connect('localhost', $mysql_user, $mysql_pass); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully<br><br>'; Next, we make a MySQL connection using the information provided by the user form submission. // Select database and grab table list mysql_select_db($mysql_db, $link) or die ("Database not found."); $tables = mysql_list_tables($mysql_db); Then, we connect to the specified database and get a list of its table names. The mysql_list_tables() function provides a quick mechanism for this. // Pull table names into an array and replace prefixes $i = 0; while ($i < mysql_num_rows($tables)) { $table_name = mysql_tablename($tables, $i); $table_array[$i] = $table_name; $i++; } Now, we want to process the results of our table list query. We’re going to parse each table name and put that information into a string array. This will make processing them much more efficient. A While loop serves our needs perfectly. // Pull table names into another array after replacing prefixes foreach ($table_array as $key => $value) { $table_names[$key] = replace_prefix($value, $table_prefix); } Finally, we are going to take each element from this array and build a new array after changing the prefix. We will need to create the replace_prefix() function that makes this all possible.
blog comments powered by Disqus |
|
|
|
|
|
|
|