WebToTell
MySQLi Connect - Printable Version

+- WebToTell (http://www.webtotell.com)
+-- Forum: PHP for beginners and advance users.PHP Code samples, applications. (http://www.webtotell.com/Forum-PHP-for-beginners-and-advance-users-PHP-Code-samples-applications)
+--- Forum: PHP (http://www.webtotell.com/Forum-PHP)
+---- Forum: MySQL Database (MariaDB) (http://www.webtotell.com/Forum-MySQL-Database-MariaDB)
+---- Thread: MySQLi Connect (/Thread-MySQLi-Connect)



MySQLi Connect - turgam - 03-07-2019

MySQLi is new OOP extension for php, most php programmers agreed that MySQL extension for php is old and not secure. There are many advantages to use MySQLi extention over MySQL. 

// mysqli, procedural way
$mysqli = mysqli_connect( 'localhost', 'username', 'password', 'database');

and
// mysqli, object oriented way
$mysqli = new mysqli( 'localhost', 'username', 'password', 'database');


Here is a most easiest php example to connect to MySQL with MySQLi extension. 

PHP Code:
<?php
$connection 
mysqli_connect("host","user","password","db");

// Check connection
if (mysqli_connect_errno()) {
 echo 
"Failed to connect to MySQL: " mysqli_connect_error();
 }
?>