From the course: PHP: Object-Oriented Programming with Databases
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Connect to the database - PHP Tutorial
From the course: PHP: Object-Oriented Programming with Databases
Connect to the database
- [Instructor] Now that we have our database credentials installed, let's see how we connect to the database using object-oriented programming. First, let's begin by reviewing the procedural version which we've used to connect to the databases with PHP up until now. To do that, we used a function called mysqli_connect and we passed in several arguments for the server, the user, the password, and the database name. That function returns back a database handle which can then be used to connect to the database in the future. It opens up a connection and we're able to then work with that connection going forward. So for example if we want to query the database, we can call another function mysqli_query. We pass in that database handle as well as the SQL that we want to query. This is a procedural style. There's no object-oriented programming here, and we're just calling basic PHP functions. The mysqli adapter also has an object-oriented version as well as the procedural version. In order…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.