Retrieve or fetch data from database in php using mysql


CODE


  • index.php
  • <?php

  • $hostname = 'localhost';
  • $username = 'root';
  • $password = '';
  • $databasename = 'testing';

  • $username1 = "master-tech";
  • $password1 = "123";

  • //password encrypt 
  • $password1 = md5($password1);

  • $u_name = 'hello908';

  • $master = mysqli_connect($hostname, $username, $password, $databasename); //database conneciton

  • if($master) {
  • echo "connection is established!..";
  • //insert data
  • $query = "SELECT * FROM `login`"; 
  • //execute
  • $run = mysqli_query($master, $query);
  • if($run) {
  • ?>
  • <table border="2">
  • <tr>
  • <th>Id</th>
  • <th>Username</th>
  • <th>Password</th>
  • </tr>
  • <?php
  • while($value = mysqli_fetch_assoc($run)) {
  • ?>
  • <tr>
  • <td><?php echo $value['id'] ?></td>
  • <td><?php echo $value['username'] ?></td>
  • <td><?php echo $value['password'] ?></td>
  • </tr>

  • <?php
  • }
  • ?>
  • </table>
  • <?php

  • }
  • else{
  • echo "<br>no data update";
  • }

  • }
  • else {
  • echo "connection is not established!..";
  • }



  • ?>

No comments