Guest User

Untitled

a guest
Mar 19th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. Class Conexao extends Config {
  2.  
  3. private $bd_host;
  4. private $bd_user;
  5. private $bd_user_pass;
  6. private $bd_base;
  7. private $conexao;
  8.  
  9. function __construct() {
  10.  
  11. $this->bd_host = self::BD_HOST;
  12. $this->bd_user = self::BD_USER;
  13. $this->bd_user_pass = self::BD_USER_PASS;
  14. $this->bd_base = self::BD_BASE;
  15.  
  16. try {
  17.  
  18. if (is_null($this->conexao)) {
  19. $this->conectar();
  20. }
  21. } catch (PDOException $e) {
  22.  
  23. echo "ERROR GERADO AO CONECTAR COM BD: " . $e->getMessage();
  24. }
  25. }
  26.  
  27. private function conectar() {
  28.  
  29. $options = [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"];
  30.  
  31. $this->conexao = new PDO("mysql:host={$this->bd_host};dbname={$this->bd_base}", $this->bd_user, $this->bd_user_pass, $options);
  32. }
  33.  
  34. function executeSQL($query, array $params = NULL) {
  35. $this->obj = $this->getConexao()->prepare($query);
  36.  
  37. if (!empty($params)) {
  38. return $this->obj->execute($params);
  39. }
  40.  
  41. return $this->obj->execute();
  42. }
  43.  
  44. function getConexao() {
  45. return $this->conexao;
  46. }
  47.  
  48. }
  49.  
  50. function registrarRemessaBd($time_insert){
  51. $query = "INSERT INTO caf_remessa (time_insert) VALUE (?)";
  52. $params = array($time_insert);
  53.  
  54. $conexao = new Conexao();
  55.  
  56. $conexao->executeSQL($query, $params);
  57.  
  58. return $conexao->getConexao()->lastInsertId();
  59.  
  60. }
Add Comment
Please, Sign In to add comment