Connecting to MySQL using in PHP

This example connects to the database blogger at the address you can type localhost instead) with the user admin and the password abcdefg. Then issues a query to select all rows in the table blog_posts, and prints the field value of title and post of each row. Lastly, it closes the database connection.

// Check connection
if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();

$result = mysqli_query($con,"SELECT * FROM blog_posts");

while($row = mysqli_fetch_array($result))
  echo $row['title'] . " " . $row['post'];
  echo "<br>";

Search within Codexpedia

Custom Search

Search the entire web

Custom Search