public $connection; private $servername = ""; private $username = ""; private $password = ""; private $database = ""; public function connect() { try { $this->connection = new PDO("mysql:host={$this->servername};dbname={$this->database}", $this->username, $this->password); // set the PDO error mode to exception $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //$this->logger->writeLog('MySQL Connection Success'); return $this->connection; } catch (PDOException $e) { $this->logger->writeLog('MySQL Connection failed'); return false; } } public function gettempleDetails($temple_id) { $this->connect(); $query = "SELECT * FROM temples WHERE id=" . $temple_id . ""; $stmt = $this->connection->prepare($query); $result = $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); return $results; } } $rpt = new temples(); $rpt->getsingletemple();
{ public $connection; private $servername = ""; private $username = ""; private $password = ""; private $database = ""; public function connect() { try { $this->connection = new PDO("mysql:host={$this->servername};dbname={$this->database}", $this->username, $this->password); // set the PDO error mode to exception $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //$this->logger->writeLog('MySQL Connection Success'); return $this->connection; } catch (PDOException $e) { $this->logger->writeLog('MySQL Connection failed'); return false; } } public function addNewTemple($name, $address, $latitude, $longitude, $description, $temple_type) { $this->connect(); $query = "INSERT INTO submitted_temples (id, name, type, description, latitude, longitude, address, image, status) VALUES ('','" . $name . "','" . $temple_type . "','" . $description . "','" . $latitude . "','" . $longitude . "','" . $address . "','', '1')"; $stmt = $this->connection->prepare($query); $result = $stmt->execute(); return $result; } } $rpt = new temples(); $rpt->addTemple();
private $servername = ""; private $username = ""; private $password = ""; private $database = ""; public function connect() { try { $this->connection = new PDO("mysql:host={$this->servername};dbname={$this->database}", $this->username, $this->password); // set the PDO error mode to exception $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //$this->logger->writeLog('MySQL Connection Success'); return $this->connection; } catch (PDOException $e) { $this->logger->writeLog('MySQL Connection failed'); return false; } } public function gettemples($latitude, $longitude, $distance, $templetype, $limitno) { $this->connect(); // $query = "SELECT * FROM temples"; $query = "SELECT *, ( 6371 * acos( cos( radians(" . $latitude . ") ) * cos( radians( latitude ) ) * \n\t\t\tcos( radians( longitude ) - radians(" . $longitude . ") ) + sin( radians(" . $latitude . ") ) * \n\t\t\tsin( radians( latitude ) ) ) ) AS distance FROM temples HAVING\n\t\t\tdistance < " . $distance . " ORDER BY RAND() LIMIT 0 , " . $limitno . ""; $stmt = $this->connection->prepare($query); $result = $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); return $results; } } $rpt = new temples(); $rpt->getalltemples();