Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('../cfg/config.php');
- class Process {
- /**
- * @var PDO
- */
- private $conn = null;
- /**
- * @var PDOException
- */
- public $error = null;
- private $host = DB_SERVER;
- private $user = DB_USER;
- private $pass = DB_PASS;
- private $db = DB_NAME;
- public function __construct() {
- ini_set('mysql.connect_timeout', 300);
- ini_set('default_socket_timeout', 300);
- $this->connect();
- }
- private function connect() {
- $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->db;
- $options = [
- PDO::ATTR_PERSISTENT => true,
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- ];
- try {
- $this->conn = new PDO($dsn, $this->user, $this->pass, $options);
- } catch(PDOException $e) {
- $this->error = $e->getMessage();
- }
- return $this->conn;
- }
- public function query($sql, $params = null) {
- preg_match('/SELECT/', $sql) ? $select = true : $select = false;
- $connect = $this->conn->getAttribute(PDO::ATTR_CONNECTION_STATUS);
- echo "CONNECTION STATUS::: " . $connect;
- if($this->error == null) {
- $query = $this->conn->prepare($sql);
- $query->execute($params);
- $query ? (!$select ? $results = true : $results = $query->fetchAll(PDO::FETCH_ASSOC))
- : $results = false;
- } else {
- $results = $this->error;
- }
- return $results;
- }
- }
- class Arrays {
- public $family = [];
- /**
- * @var Process
- */
- private $db;
- public function __construct() {
- $this->db = new Process();
- }
- public function setFamily() {
- $a = [];
- $sql = "SELECT familyNick, familyName FROM budget.family ORDER BY familyOrder";
- $query = $this->db->query($sql);
- if($query != false && is_array($query)) {
- foreach($query as $k => $v) {
- $a[$v['familyNick']] = $v['familyName'];
- }
- }
- $this->family = $a;
- }
- /**
- * @return array
- */
- public function getFamily() {
- if(empty($this->family) || !isset($this->family)) {
- $this->setFamily();
- }
- return $this->family;
- }
- }
- class Options {
- public $family = [];
- /**
- * @var Arrays
- */
- private $arrays;
- public function __construct() {
- $this->arrays = new Arrays();
- }
- public function setFamily() {
- $this->family = $this->arrays->getFamily();
- }
- public function getFamilyOptions() {
- if(empty($this->family)) {
- $this->setFamily();
- }
- $options = [];
- foreach($this->family as $famNick => $famName) {
- $options[] = "<option class='family' value='$famNick'>" . $famName . "</option>";
- }
- return $options;
- }
- }
- $test = new Options();
- $family = $test->getFamilyOptions();
- var_dump($family);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement