From the course: Database Foundations: Application Development
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Use if/else to handle errors
From the course: Database Foundations: Application Development
Use if/else to handle errors
- [Instructor] The two scripts that we've created so far haven't responded very well if you try and run the code multiple times. To fix this, we can add in some basic error handling to our script using an if-else programming construct. Let me scroll down on my page here until I get to PHP Script 3. In this example, we're going to drop the database that we just created. This time, we're setting up the database connection variable in exactly the same way. We have the variable named db_connection and it's equal to the pg_connect function with these parameters. The only difference here is that we're connecting back to the Postgres database again, not the test database. If we connected to the test database, then we wouldn't be able to drop it, since we would have an open connection. I'm also going to set up the sql_query variable again and this time, the syntax of my sql_query will be DROP DATABASE test WITH FORCE.…
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.
Contents
-
-
-
-
(Locked)
What is PHP and Apache?2m 55s
-
Create a PHP web server10m 58s
-
(Locked)
Connect to the PHP server3m 37s
-
PostgreSQL functions4m 55s
-
(Locked)
Use PHP variables3m 4s
-
(Locked)
Use if/else to handle errors4m 53s
-
(Locked)
Add data to a database4m 7s
-
(Locked)
Format SELECT query results6m 24s
-
(Locked)
Filter results with form controls5m 40s
-
(Locked)
Add data to a table with form controls5m 29s
-
(Locked)
-
-