From the course: Database Foundations: Application Development

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Use PHP variables

Use PHP variables

- [Instructor] We can make use of PHP variables to help us reuse elements in our code. PHP variables all start with a dollar sign and then you can give them a unique name. Let's scroll down on our script page here down to script number two and take a look. Now in this example, we're going to add a table to the database that we just created. We need to perform similar tasks as before. First, we're going to connect to the database server and then send it a query, but we can use variables to hold the details of our PostgreSQL functions. First, I'm going to create a new variable called DB Connection. The name here starts with the dollar side. That's how I know that it's a PHP variable. Then, I can set its value to the PG Connect function followed by all of these parameters. We're connecting to the same server using the same port and the same username and password as before. The only difference here is that this time…

Contents