| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- namespace MGModule\DNSManager2\mgLibs\MySQL;
- use MGModule\DNSManager2\mgLibs\custom\helpers as helpers;
- /**
- * MySQL Results Class
- *
- * @author Michal Czech <michael@modulesgarden.com>
- */
- class result
- {
- /**
- *
- * @var PDOStatement
- */
- private $result;
-
- /**
- * Use PDO for Connection
- *
- * @var boolean
- */
- static private $usePDO = false;
-
- /**
- * Constructor
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param PDOStatement $result
- * @param int $id
- */
- function __construct($result,$id = null) {
- if(is_a($result,'PDOStatement'))
- {
- self::$usePDO = true;
- }
-
- $this->result = $result;
- $this->id = $id;
- }
-
- /**
- * Fetch one record
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return array
- */
- function fetch()
- {
- return $this->result->fetch(\PDO::FETCH_ASSOC);
- }
-
- /**
- * Fetch All Records
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return array
- */
- function fetchAll()
- {
- if(self::$usePDO)
- {
- return $this->result->fetchAll(\PDO::FETCH_ASSOC);
- }
- else
- {
- $result = array();
- while($row = $this->fetch())
- {
- $result[] = $row;
- }
- return $result;
- }
- }
- function fetchAllKeyPair()
- {
- return $this->result->fetchAll(\PDO::FETCH_KEY_PAIR);
- }
- function fetchGroup()
- {
- return $this->result->fetchAll(\PDO::FETCH_GROUP|\PDO::FETCH_UNIQUE|\PDO::FETCH_ASSOC);
- }
-
- /**
- * Fetch One Column From First Record
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @param string $name
- * @return array
- */
- function fetchColumn($name = null)
- {
- $data = $this->result->fetch(\PDO::FETCH_BOTH);
-
- if($name)
- {
- return $data[$name];
- }
- else
- {
- return $data[0];
- }
- }
-
- /**
- * Get ID Last Inserted Record
- *
- * @author Michal Czech <michael@modulesgarden.com>
- * @return int
- */
- function getID()
- {
- return $this->id;
- }
-
- function numRows()
- {
- $this->result->fetch(\PDO::FETCH_BOTH);
-
- return $this->result->rowCount();
- }
- }
|