Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1.  
  2. <?php
  3. $username = "your_name";
  4. $password = "your_password";
  5. $hostname = "localhost";
  6.  
  7. //connection to the database
  8. $dbhandle = mysql_connect($hostname, $username, $password)
  9.  or die("Unable to connect to MySQL");
  10. echo "Connected to MySQL<br>";
  11.  
  12. //select a database to work with
  13. $selected = mysql_select_db("examples",$dbhandle)
  14.   or die("Could not select examples");
  15.  
  16. //execute the SQL query and return records
  17. $result = mysql_query("SELECT id, model,year FROM cars");
  18.  
  19. //fetch tha data from the database
  20. while ($row = mysql_fetch_array($result)) {
  21.    echo "ID:".$row{'id'}." Name:".$row{'model'}."Year: ". //display the results
  22.    $row{'year'}."<br>";
  23. }
  24. //close the connection
  25. mysql_close($dbhandle);
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement