Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DB {
- public $pdo;
- private $host = DB_HOST;
- private $user = DB_USER;
- private $pass = DB_PASS;
- private $dbname = DB_NAME;
- public function __construct()
- {
- $this->connect();
- }
- private function connect()
- {
- $options = array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- );
- try {
- $this->pdo = new PDO("mysql:host=$this->host;dbname=$this->dbname;charset=utf8;", $this->user, $this->pass, $options);
- } catch(PDOException $e) {
- echo $e->getMessage();
- }
- }
- public function __sleep()
- {
- return array('dsn', 'username', 'password');
- }
- public function __wakeup()
- {
- $this->connect();
- }
- public function __destruct()
- {
- $this->connection = null;
- $this->pdo = null;
- unset($this->pdo);
- }
- // CRUD methods follow including
- function retrieve($where, $groupBy='', $order_by='') {
- $query = "SELECT * FROM `$this->table` $where $groupBy $order_by";
- $q = $this->pdo->prepare($query);
- $q->execute();
- $result = $q->fetchAll(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE,get_class($this));
- // was $result = $q->fetchAll(PDO::FETCH_CLASS,get_class($this));
- $this->query_log($query);
- $q = null;
- if ($result == 'NULL') {
- return false;
- } else {
- return $result;
- }
- } // retrieve()
- if (in_array($_GET['type'], $types)) {
- $type = $_GET['type'];
- $rsObj = new ReservedSlug;
- if ($type == 'artist') {
- $obj = new CalendarArtist;
- $slugfield = 'urlSlug';
- $namefield = 'name';
- } else if ($type == 'event') {
- $obj = new CalendarEvent;
- $slugfield = 'urlSlug';
- $namefield = 'name';
- } else if ($type == 'location') {
- $obj = new Location;
- $slugfield = 'UrlSlug';
- $namefield = 'LocationName1';
- }
- $needslug = $obj->retrieve("TRIM(`$namefield`) != '' AND (`$slugfield` = '' OR `$slugfield` IS NULL) LIMIT 0,400");
- if ($needslug) {
- foreach ($needslug as $ns) {
- $testslug = slugify($ns->$namefield);
- list($reserved) = $rsObj->retrieve("`slug` = '$testslug' AND `type` = '$type'");
- if (!$reserved) {
- list($test) = $obj->retrieve("`$slugfield` = '$testslug'");
- if ($test) {
- for ($i = 2; $i < 26; $i++) {
- list($test) = $obj->retrieve("`$slugfield` = '$testslug-$i'");
- if (!$test) {
- $slug = $testslug . '-' . $i;
- }
- }
- } else { // not found in table
- $slug = $testslug;
- }
- } else { // was reserved
- $slug = false;
- }
- echo $ns->$namefield . " gets $slug<p>";
- } // foreach needslug
- } // if needslug
- } // type found in array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement