Creazione del database e di una tabella

<html><head>
<title>Lezioncina sul PHP - 26</title>
<meta name="author" content="Ing. Stefano Salvi">
</head>
<body bgcolor=#ffffcc text=#000080 vlink=#0040cc link=#0080ff>
<table width=100% height=100%><tr>
<td width=90% valign=middle>
<h1 align=center><font size=+5>Creazione del database e di una tabella</font></h1>
</td><td width=90 valign=middle><img src=php.jpg align=right border=0
usemap=#mymap></td></tr>
<map name=mymap>
<area shape=rect coords=0,0,30,90 href=25.html>
<area shape=rect coords=30,0,60,90 href=index.html>
<area shape=rect coords=60,0,90,90 href=27.html>
</map>
<tr>
<td height=80% valign=middle align=left colspan=2>
<font size=+3>
<?php
  require "include/dbase_mysql.inc";
  // require "include/dbase_pgsql.inc";

  $conn = crea ();

  echo "-->\nTento di leggere la tabella <font color=#008000>telefono</font>\n<!-- ";
  $res = db_exec ($conn, "select * from telefono;");
  if ($res) {
    echo "-->\nIl database <font color=#008000>lezione</font> esiste\n";
    echo "gi&agrave e contiene la tabella <font color=#008000>telefono</font>. La svuoto<br>\n<!-- ";
    $res = db_exec ($conn, "delete from telefono;");
  } else {
    echo "-->\nNon ci sono riuscito - la tabella manca<br>\n";
    echo "Creo la tabella <font color=#008000>telefono</font><br>\n<!-- ";
    $res = db_exec ($conn, "create table telefono (nome text, cognome text, tel text);");
    if ($res) {
      echo "-->\nCreato la tabella <font color=#008000>telefono</font><br>\n<!-- ";
    } else {
      echo "-->\nErrore nella creazione della tabella \n";
      echo "<font color=#008000>telefono</font><br>\n<!-- ";
    }
  }
  $file = fopen ("dati.txt", "r");
  $cnt;
  echo "-->\n<ol>\n";
  while (!feof ($file)) {
    $item=fgets ($file, 1024);
    if ($item) {
      $parts=explode (" ",$item);
      $parts[2] = trim ($parts[2]);
      echo "<li>Nome <B>$parts[0]</B> Cognome <B>$parts[1]</B> Telefono <B>$parts[2]</B>\n";
      $res = db_exec ($conn, "insert into telefono values ('$parts[0]',
        '$parts[1]','$parts[2]');");
    }
  }
  echo "</ol>\n<!-- ";
  fclose ($file);

 ?>
--><h1 align=center><a href=26.s.html>Sorgente Pagina</a>][<a
href=26.1p.html>Include Postgres</a>][<a href=26.1m>Include MySQL</a>]</h1>
</font></td></tr></table>
<p align=right><i>&copy; Ing. Stefano Salvi - </i>released under <a
 href="http://www.gnu.org/licenses/fdl.txt"
 title="Testo inglese della FDL presso www.gnu.org">FDL licence</a></p>
</body>
</html>

© Ing. Stefano Salvi - released under FDL licence