Data do not send to the database

Asked

Viewed 39 times

2

So, I created a CRUD class, the code is not returning any errors, but it is not being inserted in the database. I have tried to arrange several ways, but I can’t find any way.

CRUD.class.php

class CRUD extends Connection 
    {
        private $query, $run;
        public function __construct()
        {
            parent::__construct('mysql:dbname=vamo; host=localhost','Admin','admin');
        }

        private function set_statement($s)
        {
            if (is_object(parent::con())):

                $this->query = parent::con()->prepare($s);

            else :

                die(parent::kill_with_style($s));

            endif;
        }

        private function do_run()
        {
            $this->query->execute($this->run);
        }

        public function run($r = [])
        {
            $this->run = $r;

            $this->do_run();

            return $this->query;
        }   

        public final function insert($table, $values)
        {

            $this->set_statement("INSERT INTO ".$table." SET ".$values.""); 
            return $this;
        }
    }

Connection.class.php

class Connection extends CreateArchive
    {
        private $dsn, $user, $pass,
                $con, $error_con;
        public function __construct($dsn,$user,$pass)
        {
            $this->dsn = $dsn;
            $this->user = $user;
            $this->pass = $pass;

            $this->set_con();
        }
        private function set_con()
        {
            try
            {

                $this->con = new PDO($this->dsn, $this->user,$this->pass);
                print "Conectado";

            } catch(PDOException $e) 
            {
                $this->error_con = 'Falha na conexão';

                parent::c_archive('log/', 0700,'log_con.txt','a',$e->getMessage().PHP_EOL.'{ocorreu na linha: }'.$e->getLine());
            }
        }
        public function con()
        {

            return $this->con;
        }

        public function kill_with_style()
        {
            return '<pre class=error-die>'.$this->error_con.'</pre>';
        }
    }

head php.

   $crud->insert('tbl_user','user = ?, mail = ?, pass = ?')
     ->run(['teste', '[email protected]', 12345678]);

index php.

    require_once 'config/config.php';
    require_once 'header.php';

config.php

  error_reporting(E_ALL);

date_default_timezone_set('America/Sao_Paulo');

require_once 'class/AutoLoad.class.php';

$crud = new CRUD;
  • In do_run() needs to make a treatment for mistakes, makes a print_r($this->query->errorInfo()); see if anything pops.

  • Okay buddy, I’ll test it and let you know.

  • found the error, I was very dumb, on the column’s name in the comic was 'EMAIL' I wrote 'mail'. kkkkkkk Thanks friend!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.