Connecting to the database

Other topics

Remarks:

As I showed in the example, I saved the connection to a variable to make it cleaner in code. Otherwise, when you want to query the database, you need to connect EACH time!

It makes the code a lot cleaner!

mysqli_connect

<?php

$con = mysqli_connect("localhost", "root", "", "database");

?>

Syntax:

  1. mysqli_connect("server", "user", "password", "database name");

Parameters:

ParamaterDescription
1Server host e.g. "localhost" or "127.0.0.1"
2Server username e.g. "root" or "redstonecoder"
3Server password e.g. "" or "l3g1t"
4Database name e.g. "website" or "forum"

Contributors

Topic Id: 10164

Example Ids: 31149

This site is not affiliated with any of the contributors.