Last active
December 18, 2015 21:09
-
-
Save lgoldstien/5845113 to your computer and use it in GitHub Desktop.
SOLID - S - nonSRP tasks class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Tasks - Non-SRP | |
* A task database class that does not abide by SRP | |
* @package solid | |
* @author [email protected] | |
*/ | |
class tasks { | |
/** | |
* @var connection | |
*/ | |
private $connection; | |
/** | |
* __construct | |
*/ | |
function __construct( $db_host, $db_user, $db_pass, $db_name ) { | |
/** | |
* Make the connection | |
*/ | |
$this->connection = new mysqli( $db_host, $db_user, $db_pass, $db_name ); | |
} | |
/** | |
* list | |
* List all the tasks in the database | |
*/ | |
public function list() { | |
// The sql statement | |
$sql = "select `name`, `duedate`, `priority`, `complete` from tasks"; | |
// Run the query | |
$result = $this->connection->query( $sql ); | |
// Return the result | |
return $result->fetch_all | |
} | |
} | |
$tasks = new tasks( 'localhost', 'username', 'password', 'tasks' ); | |
$tasks_list = $tasks->list(); | |
print_r( $tasks_list ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment