Guest User

Untitled

a guest
Jul 18th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. ├── app
  2. └── Conn
  3. └── Conn.php
  4. └── vendor
  5. └── composer
  6. └── autoload.php
  7. └── composer.json
  8. └── index.php
  9. └── README.md
  10.  
  11. <?php
  12.  
  13. namespace LelvtexConec;
  14.  
  15. class Conn
  16. {
  17. private $user;
  18. private $pass;
  19. private $dbsa;
  20. private $host;
  21.  
  22. private $connon;
  23. private $conn;
  24.  
  25.  
  26. //CONSTRUCTOR
  27.  
  28. public function __construct($user, $pass, $dbsa, $host)
  29. {
  30. $this->connect($user, $pass, $dbsa, $host);
  31. }
  32.  
  33.  
  34. //PRIVATE METHODS
  35. private function connect($user, $pass, $dbsa, $host)
  36. {
  37. $this->connon = false;
  38. $this->user = strip_tags(trim($user));
  39. $this->pass = strip_tags(trim($pass));
  40. $this->dbsa = strip_tags(trim($dbsa));
  41. $this->host = $host;
  42.  
  43.  
  44. try {
  45. if (!$this->connon) {
  46. $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbsa;
  47. $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',);
  48. $this->conn = new PDO($dsn, $this->user, $this->pass, $options);
  49. $this->connon = true;
  50. echo "Conectado com sucesso!";
  51. }
  52. } catch (PDOException $e) {
  53. echo $e->getMessage();
  54. }
  55.  
  56. }
  57. }
  58.  
  59. <!DOCTYPE html>
  60. <html lang="pt-br">
  61. <head>
  62. <meta charset="UTF-8">
  63. <title>Livre e Leve</title>
  64. </head>
  65. <body>
  66. <?php
  67. require 'vendor/autoload.php';
  68.  
  69. use LelvtexConecConn;
  70.  
  71. $conn = new Conn('root', '', 'livreelevevtex', 'localhost');
  72. var_dump($conn);
  73. ?>
  74. </body>
  75. </html>
  76.  
  77. <?php
  78.  
  79. // autoload_psr4.php @generated by Composer
  80.  
  81. $vendorDir = dirname(dirname(__FILE__));
  82. $baseDir = dirname($vendorDir);
  83.  
  84. return array(
  85. 'Lelvtex\' => array($baseDir . '/app'),
  86. );
  87.  
  88. {
  89. "name": "lucascar/livreelevevtex",
  90. "description": "Projeto de Teste para Livre e Leve vtex",
  91. "type": "library",
  92. "license": "MIT",
  93. "authors": [
  94. {
  95. "name": "Lucas de Carvalho",
  96. "email": "contato@lucasdecarvalho.com"
  97. }
  98. ],
  99. "minimum-stability": "dev",
  100. "autoload" : {
  101. "psr-4" : {
  102. "Lelvtex\" : "app/"
  103. }
  104. }
  105. }
Add Comment
Please, Sign In to add comment