Connecting MySQL database with PHP using Object Oriented way.
<?php $server = "localhost"; $username = "root"; $password = ""; //setting up the connection $conn = new mysqli($server, $username, $password); //checking the connection. if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected by Object Oriented way successfully";
Connected by Object Oriented way successfully
To run the script:
1.Install any local host server and start it.
2.Type the above code in the installed directory
and save it as php file.
3.In Browser,type localhost/filename.php and hit enter.
Note: The above code is not much differed from the procedural syntax whereas the PHP Data Objects (PDO) extension, a consistent interface for accessing databases requires the new Object Oriented method. It does not have the procedural interface.
Comments :