954,136 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Custom Database Admin Tool.



<?php $host = "localhost"; //Location of Mysql
$name = "michael"; //User Name for Mysql
$pass = ""; //Password for Mysql
$connect = mysql_connect ($host, $name, $pass)
or die (mysql_error());
$database = mysql_list_dbs ($connect)
or die (mysql_error()); $database_list = ""; $db_value = 0; while ($db_value < mysql_num_rows ($database))
{
$database_names[$db_value] = mysql_tablename ($database, $db_value);
$database_list .= "$database_names[$db_value]";
$tables = mysql_list_tables ($database_names[$db_value]) or die (mysql_error());
$tb_list = "";
$tb_value = 0;
while ($tb_value < mysql_num_rows($tables))
{
$table_names[$tb_value] = mysql_tablename ($tables, $tb_value);
$tb_list .= "$table_names[$tb_value]";
$tb_value++;
}
$tb_list .= "
";
$database_list .= "$tb_list";
$db_value++;
}

$database_list .= "";
echo "Database Management";
echo "$database_list"; ?>


Please type the name of the database you wish to modify!

---enter database name as seen




Please type the name of the database you wish to Create!


Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

would you be able to post the tb_create.php code

great post by the way :) :)

pansylea
Newbie Poster
2 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

I think there were some issues with tb_create, mostly I hadn't gotten it working at the time lol.

but you are more than welcome to have at it. This is a pretty old thread so you should count your lucky stars I even found the source for this!!

<?php
$host = "localhost"; //location of the mysql
$name = ""; //user name for logging into mysql
$pass = ""; //password for logging into mysql

$TBname = "$_POST[TBname]"; //name of the table for Creation
$DBname = "$_POST[DBname]"; //name of the database for working in


    $connect = mysql_connect($host, $name, $pass) or die(mysql_error());
    mysql_select_db($DBname) or die(mysql_error());
    
    $sql = "CREATE TABLE $TBname ("; //creates the table

    for ($count = 0; $count < count($_POST[field]); $count++)
       {
        $sql .= $_POST[field][$count] . " " . $_POST[type][$count];
            
            if ($_POST[auto_increment][$count]  == "y")
              {
               $additional = "NOT NULL AUTO_INCREMENT";
              }
            else
                {
                 $additional = "";
                }
            if ($_POST[primary][$count] == "y")
              {
               $additional .= ", primary key (" . $_POST[field][$count] . ")";
              }
            else
                {
                 $additional = "";
                }
            if ($_POST[length][$count] != "")
              {
               $sql .= " (" .$_POST[length][$count] . ") $additional ,";
              }
            else
                {
                 $sql .= " $additional ,";
                }
       }
// clean up the end of the string
$sql .= ")";

$result = mysql_query($sql, $connect) or die(mysql_error()); // execute the query

if ($result)
  {
   $msg = "<p>" . $TBname . "has been created</p>";
  }
echo "Adding $TBname to $DBname ....Done";
echo "Creating fields in $TBname ....Done";
echo $msg . ""; 
echo "<a href=\"http://localhost/dbadmin/db_management.php\">Return to Database Management</a>";
?>
Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

thank you for replying, good code :)

pansylea
Newbie Poster
2 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You