MySQLi Connect - Printable Version

+- WebToTell (https://www.webtotell.com)
+-- Forum: PHP for beginners and advance users.PHP Code samples, applications. (https://www.webtotell.com/Forum-PHP-for-beginners-and-advance-users-PHP-Code-samples-applications)
+--- Forum: PHP (https://www.webtotell.com/Forum-PHP)
+---- Forum: MySQL Database (MariaDB) (https://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');

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

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

PHP Code:

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