Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // classe conecta
- class conecta {
- private $hostname, $username, $password, $name_db, $mysqli, $nome, $sobrenome;
- public function __construct() {
- $this->hostname = "localhost";
- $this->username = "root";
- $this->password = "abzj6220";
- $this->name_db = "alternativa";
- }
- private function conectar() {
- $this->mysqli = new mysqli($this->hostname, $this->username, $this->password, $this->name_db);
- if ( mysqli_connect_errno() ) {
- throw new Exception('Problema ao conectar o banco de dados');
- }
- }
- public function inserir($nome, $sobrenome) {
- $this->nome = $nome;
- $this->sobrenome = $sobrenome;
- if ( !isset($this->mysqli) ) {
- $this->conectar();
- }
- if ( $stmt = $this->mysqli->prepare("INSERT INTO tabela (nome,sobrenome) VALUES (?,?)") ) {
- $stmt->bind_param("ii", $this->nome, $this->sobrenome);
- $stmt->execute();
- $stmt->close();
- return true;
- } else {
- throw new herdaException('Problema ao inserir dados');
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement