Not logged in

Your Account

php mysqli Database Connect

Home/Tutorials/php mysqli Database Connect

php mysqli Database Connect

Content by: Steve Stewart

Posted 2 months ago with 67 views

Database Connect with MySQLi

Here we are connecting to our database using mysqli.
I'm doing two ways but basically the same, simply you can have:

$db_conx = new mysqli('localhost', 'db_user', 'db_password', 'db_name');

As I tend to add more into the file like the website name and slogan amoungst other things, I use define.

define('DATAB_HOST', 'IPADDRESS'); = Add the IP address or localhost
define('DATAB_PORT', '3306'); = Normally 3306
define('DATAB_DB', 'DATABASE-NAME'); = The Database Name
define('DATAB_UNAME', 'USRNAME'); = Database Username
define('DATAB_PASS', 'DB-PASSWORD'); = Database Password

$db_conx = new mysqli(''.DATAB_HOST.':'.DATAB_PORT.'', DATAB_UNAME, DATAB_PASS, DATAB_DB);

Once you have you're database connection
You can check using the database and port checker at: databaseportcheck.php
Save the document as "dbconnection.php"