Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Pesquisa retornou 1 resultados
- array(1) {
- [0]=>
- array(16) {
- ["id"]=>
- string(1) "1"
- [0]=>
- string(1) "1"
- ["name"]=>
- string(17) "Lucas de Carvalho"
- [1]=>
- string(17) "Lucas de Carvalho"
- ["email"]=>
- string(27) "contato@lucasdecarvalho.com"
- [2]=>
- string(27) "contato@lucasdecarvalho.com"
- ["username"]=>
- string(15) "lucasdecarvalho"
- [3]=>
- string(15) "lucasdecarvalho"
- ["registred"]=>
- NULL
- [4]=>
- NULL
- ["password"]=>
- string(23) "12312312312312312312312"
- [5]=>
- string(23) "12312312312312312312312"
- ["status"]=>
- string(1) "0"
- [6]=>
- string(1) "0"
- ["registration_key"]=>
- string(13) "muasdsadaosdj"
- [7]=>
- string(13) "muasdsadaosdj"
- }
- }
- <!DOCTYPE html>
- <html lang="pt-br">
- <head>
- <meta charset="UTF-8">
- <title>Livre e Leve</title>
- </head>
- <body>
- <pre>
- <?php
- require 'vendor/autoload.php';
- require '_app/config.php';
- use LelvtexConnRead;
- $a = new Read;
- $a->exeRead('cmslcs_users');
- echo "Pesquisa retornou {$a->getRowCount()} resultados";
- echo "<hr>";
- var_dump($a->getReadResult());
- ?>
- </pre>
- </body>
- </html>
- <?php
- namespace LelvtexConn;
- class Read extends Conn
- {
- private $conn;
- private $query;
- private $result;
- private $table;
- private $read;
- private $terms;
- private $links;
- public function exeRead($table, $terms = null, $links = null)
- {
- if($terms) {
- $this->terms = htmlspecialchars(trim(strip_tags($terms)));
- }
- if (!empty($links)){
- parse_str($links, $this->links);
- }
- $this->table = htmlspecialchars(trim(strip_tags($table)));
- $this->execRead();
- }
- public function getReadResult()
- {
- return $this->result;
- }
- /*
- * O rowCount verifica quantos registros existem na database
- */
- public function getRowCount()
- {
- if ($this->read->rowCount()) {
- return $this->read->rowCount();
- }
- }
- /*
- * Prepara a query, puxando a conexão da Class Conn
- */
- private function prepareQuery()
- {
- $this->query = "SELECT * FROM {$this->table} {$this->terms}";
- $this->conn = parent::getConn();
- $this->read = $this->conn->prepare($this->query);
- }
- /*
- * Faz o bind value nos links :meulink se o $links for preenchido la em cima no exeRead
- */
- private function formatLnks(){
- if($this->links){
- foreach ($this->links as $link => $val) {
- if($link == "limit" || $link == "offset"){
- $val = (int) $val;
- }
- $this->read->bindValue(":{$link}", $val, ( is_int($val) ? PDO::PARAM_INT : PDO::PARAM_STR));
- }
- }
- }
- /*
- * Executa toda a função. primeiro ele prepara a query com o prepareQuery, depois dentro de um try catch, ele termina o que deve ser executado.
- */
- private function execRead()
- {
- $this->prepareQuery();
- try {
- $this->formatLnks();
- $this->read->execute();
- $this->result = $this->read->fetchAll();
- } catch (PDOException $e) {
- $this->result = null;
- echo "Erro na linha <b> {$e->getLine()} </b> no arquivo {$e->getFile()}: " . $e->getMessage();
- }
- }
- }
Add Comment
Please, Sign In to add comment