PHP Set 8 Flashcards
What does a child class inherit from its parent class?
All public and protected properties and methods
How is an inherited class defined?
Using the extends keyword
Ex: class Apple extends Food { }
How can an inherited method be overridden in a child class?
By redefining a method using the same name in the child class
How can method overriding or class inheritance be prevented?
Using the final keyword prevents child classes from being made from an object or a method being redefined
What is an abstract class?
A class that has at least one abstract method
What is an abstract method?
A method that is declared with the abstract keywork and not implemented in code
What is the syntax for declaring an abstract function?
abstract function name($param): returntype;
What are the rules for when a child class is inherited from an abstract class?
- The child class method must be defined with the same name and redeclare the parent abstract method
- The child class method must be defined with the same or a less restricted access modifier
- The number of required arguments must be the same but the child class can add optional arguments
What is the difference between an interface and an abstract class?
- Interfaces cannot have properties but abstract classes can
- All interface methods are abstract so they abstract keyword isn’t necessary
- All interface methods must be public
- Classes can implement an interface and inherit from another class at the same time
How do you declare an interface and how do you implement one?
Declare:
interface Animal {
functions
}
Implement:
class Cat implements Animal { }
What are the 2 methods used to connect to MySQL?
- MySQLi extension
- PDO (PHP Data Objects)
What is the main difference between MySQLi and PDO?
PDO supports various databases but MySQLi only supports MySQL
MySQLi is a but faster
PDO supports 12 different drivers but MySQLi only supports MySQL
How do you open a MySQL connection using MySQLi?
$conn = new mysqli(“localhost”, “username”, “password”, “dbName”)
How do you open a MySQL connection using PDO?
$conn = new PDO($dsn, “root”, “lsucceed168”, $options)
where $dsn = “mysql:host=localhost;dbname=name;charset=utf8mb4”
How do you create a table in MySQL?
With the CREATE TABLE statement
$sql = “CREATE TABLE MyGuests (id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )”;