Page 1 of 1

How to do it in the easiest way ? DB Management

Posted: Wed Dec 24, 2003 6:52 am
by Citizen99
I know ther is PHPmyadmin :] but i have to write a simple html/php form to list, show drop rename and create tables and search :]

I`m noob in php/mysql but write something. I have problem with put this together. I have no idea how to put all this function + drop and rename table in logical way to one form. Hmm using case ? Maybe someone write somethink like this for training THX for help.

Code: Select all

<?

// --- sometimes define can help, but not always :]

define('NL',"\n");
define('TB',' ');

// ----------------------

$host='localhost';
$tabela='users';
$kto='citizen99';
$pass='XXX';
$db_name='mydb';

// ---------------------  db connection -------------------

$moja=mysql_connect($host,$kto,$pass)
or die("Nie mozna polaczyc sie z serverem");
mysql_select_db("$db_name")
or die("Nie mozna sie polaczyc z baza");
$sql="SELECT * from $tabela";

if($filtr)
$sql.= " where $filtr";
$sql= stripslashes($sql);
print "<B>Filtr:</B> $sql <BR>\n";
print "<B>Baza:</B> $listabaz\n\n";

// --------------------- db list ----------------

 $listabaz = mysql_list_dbs( $moja );
    while( $row = mysql_fetch_row( $listabaz ) ):
    print $row&#1111;0].NL.'<BR>';
    endwhile;
  mysql_free_result( $listabaz );

print "<B>Tablica:</B> $listatab\n\n";

// ----------------------- tb list

 print "<SELECT name='$db_name'>\n";
 $listatab = mysql_list_tables($db_name);
 while ($row = mysql_fetch_row($listatab))&#123;
 foreach ($row as $lista)
 &#123;
 print "<OPTION>$lista</OPTION>\n";
 &#125;
 &#125;
   
 print "</SELECT><BR><BR>\n\n";
  
// ------------------- CREATE z dropem jesli exist ---------------

 $sql = 'DROP TABLE IF EXISTS `awaria_awaria`';
 echo DB dropped alles OK;
 mysql_query( $sql, $moja );

 $sql = 'CREATE TABLE `awaria_awaria` (
      `kompid` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
	`opis` VARCHAR( 150 ) NOT NULL,
	PRIMARY KEY ( `kompid` )
	 )';
 echo 'Tworzenie Tabeli: ''awaria_awaria''....';
 mysql_query( $sql, $moja );
						       
// ---------------------- show tabele -----------------------

$wynik=mysql_query($sql) or die("sql_error");

print "<TABLE border =1><TR bgcolor=gray>\n";

$pole = mysql_list_fields($db_name, $tabela, $moja);
$kolumna = mysql_num_fields($pole);
   for ($i = 0; $i < $kolumna; $i++)
print ("<TD>".mysql_field_name($pole, $i)."</TD>\n");

while ( $costam=mysql_fetch_row($wynik))&#123; 

print "<TR>\n";
foreach ($costam as $cosinnego) 
&#123;
print "<TD>$cosinnego</TD>\n";
&#125;
&#125;

mysql_close($moja);

?>

</TABLE>
</BODY>
</HTML>