PHP - Mysql SELECT Statement

the mysql select statement allows you to retrieve zero or more rows from tables or views.

the select statement returns a result that is a combination of columns and rows, which is also known as a result-set.

the data can be fetched from users tables by executing select statement through php function mysqli_query().

the mysqli_fetch_array() function fetches a result row as an associative array.

note : field names returned by this function are case-sensitive.

the mysqli_fetch_array() returns an array of strings that corresponds to the fetched row or null.

 <?php
    
          $host_name = "localhost";
               
          $username_value = "books";
               
          $password_value = "342312";
               
          $dbname_value = "javabooks";               
               
     // "---mysqli procedural style use to connect mysql database server -"
                
 $con_obj = mysqli_connect( $host_name, $username_value, $password_value, 
 
                                                                                    $dbname_value);

  if( $con_obj ){ echo  "<h1>connection success <h1>";
                  
                 }else {              
     
  echo  "<h2>connection  fail error --:". mysqli_connect_error() ."</h2>"; 
  
                   }
  
      $query  = "select  *  from  users";
      
      $array  = mysqli_query( $con_obj, $query);
      
if( ! $array ){ echo "could nod get data : ".mysqli_error( $con_obj );}
      
      while( $rows = mysql_fetch_array( $array )){
      
           echo   ($rows['firstname']);
           
           echo   "\br". $rows['lastname'];
           
           echo   "\br". $rows['salary];
           
        }     
  ?>
   shyam
   sing
   95492

PHP  Mysql Where statement- Filters data

the mysql where clause is used to filter records

the where clause allows you to specify exact rows to select based on given conditions.

in the example below, selects all rows from the "users" table where "lastname ='nehra' ":

 <?php
    
          $domain = "localhost";
               
          $name = "apps";
               
          $pass = "12eve";
               
          $db_name = "appsstore";               
               
     // ":---mysqli procedural style use to connect mysql database server ____"
                
 $con_object = mysqli_connect( $domain, $name, $pass, $db_name);

  if( $con_object ){ echo  "<h3>connection to mysql server success </h3>";
                  
                 }else {              
     
  echo  "<h4>error prons -- : ". mysqli_connect_error() ."</h4>"; 
  
                   }
  
      $query  = "select  *  from  users  where  lastname='nehra'";
      
      $array  = mysqli_query( $con_object, $query);
      
if( ! $array ){ echo "could nod get data : ".mysqli_error( $con_object );}
      
      while( $rows = mysql_fetch_array( $array )){
      
         echo  $rows['firstname']."  ". $rows['lastname];
           
        }     
  ?>
   output : krishna  nehra