setting up database class in php OOP Flashcards

1
Q

MySQLi extension(the “i” stands for )

A

improved

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

PDO Stands for

A

PHP DATA OBJCETS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Mysqli and PDO difference

A

PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Steps in creating the Class

A
  1. Create your file inside the classes folder or a like (the folder that will be called in class autoloading using SPL)
  2. Declare a private property/attributes of the following
    Hostname
    DB Username
    DB Password
    DB Name
  3. Create a protected function e.g connect() or a user-defined method name.
  4. Instantiate a property named Data Source Name or dsn or any user-defined property name. (mysql:hostname=. +this ;dbname + this
  5. Instantiate a property named PDO as new PDO or any property defined by the user. Parameter of new PDO contains the Data Source Name, Class/this Property – DB Username and DB Password
  6. Set the Attribute of the PDO and call the PDO class directly using its default associated method e.g $pdo-> PDO::
    ATTR_DEFAULT_FETCH_MODE
    FETCH_ASSOC
    Return the property name PDO
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

ATTR_DEFAULT_FETCH_MODE

A

PDO::ATTR_DEFAULT_FETCH_MODE Fetches a row from a result set associated with a PDOStatement object. The mode parameter determines how PDO returns the row.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

FETCH_ASSOC

A

PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Creating a Class that Extends your DB class file (Displaying records from your Database)

A
  1. Create a new class file inside classes folder for SPL to auto detect it.
  2. Create a public function that will display the records in the database.
    Instantiate a property name SQL or any user-defined property that will show Structured Query Language of Selecting the records from the DB Table.
    Declare a property name or statement that will call the class’ connection method(from your db class) and will query the sql statement
    Use looping statement e,g while ($row = statement->fetch())
    Inside of your looping statement echo the fields you want to display
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Displaying Record by requirement category

A
  1. Create a public function that is parameterized by what you are requiring for Displaying purposes. (any user-defined method with properties inside parenthesis)
  2. Instantiate a property name SQL or any user-defined property that will show Structured Query Language of Selecting the records from the DB Table with a display condition.
  3. Declare a property name or statement that will call the class’ connection method(from your db class) and will prepare the sql statement
  4. Create a statement that will execute the parameterized properties
  5. Create a property name that will fetch the record based on the prepared statement e.g $row = $statement->fetchAll();
  6. Use a looping statement - this time use foreach e,g $row as $row
  7. Echo the $row[‘fields in your database’];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Inserting New Record

A
  1. Create a public function that is parameterized by what you are requiring for Displaying purposes. (any user-defined method with properties inside parenthesis)
  2. Instantiate a property named SQL or any user-defined property that will show Structured Query Language of inserting records to the DB
  3. Declare a property name or statement that will call the class’ connection method(from your db class) and will prepare the sql statement
  4. Create a statement that will execute the parameterized properties
How well did you know this?
1
Not at all
2
3
4
5
Perfectly