Created
          December 28, 2020 02:55 
        
      - 
      
- 
        Save barmgeat/13d635bb1cec308a67f385f6b244a21f to your computer and use it in GitHub Desktop. 
    MySQLi Procedural.php
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| $servername = "localhost"; | |
| $username = "username"; | |
| $password = "password"; | |
| $dbname = "myDB"; | |
| // Create connection | |
| $conn = mysqli_connect($servername, $username, $password, $dbname); | |
| // Check connection | |
| if (!$conn) { | |
| die("Connection failed: " . mysqli_connect_error()); | |
| } | |
| $sql = "SELECT id, firstname, lastname FROM MyGuests"; | |
| $result = mysqli_query($conn, $sql); | |
| if (mysqli_num_rows($result) > 0) { | |
| // output data of each row | |
| while($row = mysqli_fetch_assoc($result)) { | |
| echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; | |
| } | |
| } else { | |
| echo "0 results"; | |
| } | |
| mysqli_close($conn); | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment