usersDataSource
in package
usersDataSource class
usersDataSource provides the data access capabilities for the Users class.
To build a data access class for Users, the following 5 methods must exist. getPassword(username) getAllUsers() getARecord update
Additionally, where appropriate, the following function is useful buildTable()
This particular instance provides an interface to MySQL using the mysqli libraries.
Create an instance of this, then pass the variable to several Users calls.
Tags
Table of Contents
- $configuration : array<string|int, string>
- __construct() : null
- constructor for an instance of the class
- getAllUsers() : array<string|int, string>
- retrieves all users from the database
- getARecord() : array<string|int, string>
- Get a record from the database
- getPassword() : array<string|int, string>
- Retrieves the password field from table
- update() : mysqli_result|bool
- updates row in database with $newData
Properties
$configuration
protected
array<string|int, string>
$configuration
= array()
Contains the configuration for the class
May be modified by the calling program. Must be replicated in userDataSource class
Methods
__construct()
constructor for an instance of the class
public
__construct([array<string|int, string> $dbDef = array() ]) : null
If $dbConnection is not null, will be used for database access If $dbLoginInfo is not null, will override $dbConnection, make a new connection and use that.
If $dbDef is set, will be merged with $configuration
Parameters
- $dbDef : array<string|int, string> = array()
-
Array to be merged with $configuration
Return values
null —getAllUsers()
retrieves all users from the database
public
abstract getAllUsers() : array<string|int, string>
Retrieves all data for all users from table
Return values
array<string|int, string> —array of array of rows/columns
getARecord()
Get a record from the database
public
abstract getARecord(array<string|int, string> $whereFields[, array<string|int, string> $fieldList = null ]) : array<string|int, string>
Gets a single record from the database which matches $field containing $username. If more than one record is returned, will return the first one
Parameters
- $whereFields : array<string|int, string>
-
column=>value pairs for where clause
- $fieldList : array<string|int, string> = null
-
a list of columns to return. If empty, returns all columns
Return values
array<string|int, string> —a hash containing fieldname=>value pairs from fetch_assoc
getPassword()
Retrieves the password field from table
public
abstract getPassword(string $username) : array<string|int, string>
Note that the password is stored as a hash in the table
Parameters
- $username : string
-
username used to find record
Return values
array<string|int, string> —an array of values key/value pairs
update()
updates row in database with $newData
public
abstract update(array<string|int, string> $newData) : mysqli_result|bool
Parameters
- $newData : array<string|int, string>
-
fieldname/value pairs to be updated in table
Return values
mysqli_result|bool —The mysqli result from a query