Shelby Week 2 Lab
Week 2 Lab
Part 1
- 1. PDO allows us to access multiple databases with API, has usable prepared statements, and simplifies the code needed to pull data from a database.
- 2.PDO is stored within a variable and is only called once whereas mysqli functions can be used multiple times anywhere within the code. PDO can fetch data from arrays effectively while mysqli requires steps to call the array and then narrow down results.
- 3. Two of the three benefits of PDO are security and usability. Security from prepared statements allow placeholders for data, these placeholders will have no data attached to them. This is important as data from the database is withheld from use within queries allowing obscurity from outside users. PDO has the benefit of usability by being called on as a variable once and using less code with API functions to grab data from a database.
Part 2
- This establishes a connection with a database, the database username with password, and sets the charset for the page.
- This creates a new PDO variable as well as a connections between the PDO variable and the database.
- This allows the display of errors for pages related to files within the 'http://www.webstudentwork.com/codex/' directory.
- The function myHash grabs the passwords from within the database and hashes them while adding salt. In our lab example this means we are combining the password with random characters (salt) and scrambling them 100000 times (hash). We then concatenate the hash and salt into the hash variable itself so we can remove that from the password later when it is needed.