Site icon DataFlair

How to Read and Select Data in PHP MySQL

Program 1

<html>
<body>
    <center>
<pre>

<?php
      $servername="localhost";
      $username="root";
      $password="";
      $dbname="Library";
      $mycon=mysqli_connect($servername,$username,$password,$dbname);
      if($mycon->connect_error)
      die("Connection failed....");
     else
    { 
          echo "Connection success......";
          $sql="select * from student";
          //  mysqli_query($mycon,$sql);
           $record=$mycon->query($sql);
           if(mysqli_num_rows($record)>0)
           {
              // print_r($record);
                echo "<br>";
                while($row=mysqli_fetch_assoc($record))
                {
                        echo $row['sid']."  ".$row['sname']."  ".$row['course']."<br>";

                }
           }  
           else
              echo "No Record found";

    }  

?>
</pre>
</center>
</body>
</html>

 

Exit mobile version