Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ├── app
- └── Conn
- └── Conn.php
- └── vendor
- └── composer
- └── autoload.php
- └── composer.json
- └── index.php
- └── README.md
- <?php
- namespace LelvtexConec;
- class Conn
- {
- private $user;
- private $pass;
- private $dbsa;
- private $host;
- private $connon;
- private $conn;
- //CONSTRUCTOR
- public function __construct($user, $pass, $dbsa, $host)
- {
- $this->connect($user, $pass, $dbsa, $host);
- }
- //PRIVATE METHODS
- private function connect($user, $pass, $dbsa, $host)
- {
- $this->connon = false;
- $this->user = strip_tags(trim($user));
- $this->pass = strip_tags(trim($pass));
- $this->dbsa = strip_tags(trim($dbsa));
- $this->host = $host;
- try {
- if (!$this->connon) {
- $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbsa;
- $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',);
- $this->conn = new PDO($dsn, $this->user, $this->pass, $options);
- $this->connon = true;
- echo "Conectado com sucesso!";
- }
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- }
- <!DOCTYPE html>
- <html lang="pt-br">
- <head>
- <meta charset="UTF-8">
- <title>Livre e Leve</title>
- </head>
- <body>
- <?php
- require 'vendor/autoload.php';
- use LelvtexConecConn;
- $conn = new Conn('root', '', 'livreelevevtex', 'localhost');
- var_dump($conn);
- ?>
- </body>
- </html>
- <?php
- // autoload_psr4.php @generated by Composer
- $vendorDir = dirname(dirname(__FILE__));
- $baseDir = dirname($vendorDir);
- return array(
- 'Lelvtex\' => array($baseDir . '/app'),
- );
- {
- "name": "lucascar/livreelevevtex",
- "description": "Projeto de Teste para Livre e Leve vtex",
- "type": "library",
- "license": "MIT",
- "authors": [
- {
- "name": "Lucas de Carvalho",
- "email": "contato@lucasdecarvalho.com"
- }
- ],
- "minimum-stability": "dev",
- "autoload" : {
- "psr-4" : {
- "Lelvtex\" : "app/"
- }
- }
- }
Add Comment
Please, Sign In to add comment