CONECTAR HTML CON BASE MYSQL EN PHP

CREAR UNA CARPETA LLAMADA academia


1 crear archivo index.html

<!DOCTYPE html>

<html lang="es">

<head>
<title>Conexion a Base de datos</title>
<meta charset="utf-8" />

</head>

<body>

 <h1>BASE DE DATOS</h1>
 <form method="POST" action=2conexion.php">
 servidor: <input type="text" name="ser"/></br>
 usuario: <input type="text" name="usu"/></br>
 clave: <input type="text" name="pas"/></br>
 base de datos: <input type="text" name="bdb"/></br>
 digite la consulta: <input type="text" name="cons"/></br>

 <input type="submit" name="Conectar" vale="conectar" /><br><br>
 

<footer>
        Creado por alvaro
</footer>
</body>
</html>

2 crear archivo conexion.php para conectar datos

<?php
if (isset($_POST{"Conectar"]))
   { $ser=$_POST["ser"];
     $usu=$_POST["usu"];
     $pas=$_POST["pas"];
     $dbd=$_POST["dbd"];
     $cons=$_POST["cons"];
     include 'cone.php';
   
     $sql=new conecta ($ser,$usu,$pas,$dbd);
     $consu=$sql->CONSU($CONS);
     $num = mysqli_num_rows($consu);
     if ($num>0)
         { echo "table">;
           echo "<tr>";
           echo "<th> codigo </th><th> nombre </th>";
           echo "</tr>";
           while ($row=mysqli_fetch_array($consu))
               { echo "<tr>";
                 echo "<td>".$row['codest']."</td><td>".$row['nomest']."<td>";
                 echo "</tr>";
               }
           echo "</table>";
         }
         
   }

?>

3 crear archivo cone.php para conectar base

<?PHP
class conecta extends MYSQLi
 { public $host,$user,$password,$database,$connection;
   public function _construct($host,$user,$password,$database)
         { $this->host=$host;
           $this->user=$user;           
           $this->password=$password;
           $this->database=$database;
           $this->connect_me();
         }
   private function connect_me()
         { $this->connection=$this->connect($this->host,$this->user,
                                            $this->password,$this->database);
           if ($this->connect_error)
              die($this->connect_error);
         }
   public function consu($cond)
      { $result=$this->query($cons);
        if ($this->error)
           { return $this->error;
           }
        else
           { return $result;
           }
         }
  }
?>
         



Share this

Related Posts

Previous
Next Post »