Advertisement
Guest User

SQL_Connect

a guest
Aug 24th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "";
  7. $dbname = "customer_order";
  8.  
  9. // Create connection
  10.  
  11. // Check connection
  12.  
  13. function connect($servername, $username, $password)
  14. {
  15.      return mysqli_connect($servername, $username, $password);
  16. }
  17.  
  18. $conn = connect($servername, $username, $password);
  19.  
  20. echo "Connected successfully";
  21. echo "</br>";
  22.  
  23. //run a select query
  24.     $sql = 'SELECT username FROM users';
  25.   $result = mysqli_query($conn,$sql);
  26.    
  27.   //output data in a table
  28.  // echo "<table>\n";
  29.       while ($row = mysqli_fetch_object($result))
  30.       {    
  31.          /* echo "<tr>\n";
  32.               foreach ($row as $val)
  33.                  {
  34.                   echo "<td>$val</td>\n";
  35.                  }
  36.           echo "</tr>\n"; */
  37.           print_r($row);
  38.       }
  39.  // echo '</table>';
  40.  
  41.  
  42.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement