Daniia/Daniia.php
final public function insert(array $datas, bool $returning_id = false) {
      if (is_array($datas) && count($datas)) {
         if (!is_array(@$datas[0]))
            $datas = [$datas];

         $this->connection();
         $this->columns();

         $placeholders = [];
         $this->placeholder_data = [];

         foreach ($datas as $data) {
            $placeholder = [];
            foreach($this->columnsData as $column) {
               if(isset($data[$column])) {
                  $placeholder[$column] = "NULL";
                  if ( gettype($data[$column])==='boolean' )
                     $placeholder[$column] = $data[$column] ? 'TRUE' : 'FALSE';
                  elseif ( $data[$column]!=='' && $data[$column]!==NULL ) {
                     $placeholder[$column] = "?";
                     $this->placeholder_data[] = $data[$column];
                  }
               }
            }
            $placeholders[] = "(".implode(",", $placeholder).")";
         }

         $columns = "(".implode(",", array_keys($placeholder)).")";

         $placeholders = implode(",", $placeholders);


         $schema = '';
         $returning = '';
         if ($this->driver=='pgsql' && $this->schema) {
            if (!preg_match('/\./', $this->table)) {
               $schema = $this->schema ? $this->schema.'.' : '';	
            }
            $returning = $returning_id ? 'RETURNING '.$this->primaryKey : '';
         }

         $this->last_sql = $this->sql = "INSERT INTO {$schema}{$this->table} {$columns} VALUES {$placeholders} {$returning};";
         
         $this->fetch();

         $this->data = $this->rows;

         $this->reset();

         if ( $this->tableOrig!==NULL ) {
            $this->table = $this->tableOrig;
         }

         $error = $this->error();
         return $error['message'] ? FALSE : TRUE;
      }
      return FALSE;
   }
final public function insert(array $datas, bool $returning_id = false) {
      if (is_array($datas) && count($datas)) {
         if (!is_array(@$datas[0]))
            $datas = [$datas];

         $this->connection();
         $this->columns();

         $placeholders = [];
         $this->placeholder_data = [];

         foreach ($datas as $data) {
            $placeholder = [];
            foreach($this->columnsData as $column) {
               if(isset($data[$column])) {
                  $placeholder[$column] = "NULL";
                  if ( gettype($data[$column])==='boolean' )
                     $placeholder[$column] = $data[$column] ? 'TRUE' : 'FALSE';
                  elseif ( $data[$column]!=='' && $data[$column]!==NULL ) {
                     $placeholder[$column] = "?";
                     $this->placeholder_data[] = $data[$column];
                  }
               }
            }
            $placeholders[] = "(".implode(",", $placeholder).")";
         }

         $columns = "(".implode(",", array_keys($placeholder)).")";

         $placeholders = implode(",", $placeholders);


         $schema = '';
         $returning = '';
         if ($this->driver=='pgsql' && $this->schema) {
            if (!preg_match('/\./', $this->table)) {
               $schema = $this->schema ? $this->schema.'.' : '';	
            }
            $returning = $returning_id ? 'RETURNING '.$this->primaryKey : '';
         }

         $this->last_sql = $this->sql = "INSERT INTO {$schema}{$this->table} {$columns} VALUES {$placeholders} {$returning};";
         
         $this->fetch();

         $this->data = $this->rows;

         $this->reset();

         if ( $this->tableOrig!==NULL ) {
            $this->table = $this->tableOrig;
         }

         $error = $this->error();
         return $error['message'] ? FALSE : TRUE;
      }
      return FALSE;
   }
final public function insert ( array $ datas , bool $ returning_id = false ) { if ( is_array ( $ datas ) && count ( $ datas ) ) { if ( ! is_array ( @ $ datas [ 0 ] ) ) $ datas = [ $ datas ] ; $ this -> connection ( ) ; $ this -> columns ( ) ; $ placeholders = [ ] ; $ this -> placeholder_data = [ ] ; foreach ( $ datas as $ data ) { $ placeholder = [ ] ; foreach ( $ this -> columnsData as $ column ) { if ( isset ( $ data [ $ column ] ) ) { $ placeholder [ $ column ] = "NULL" ; if ( gettype ( $ data [ $ column ] ) === 'boolean' ) $ placeholder [ $ column ] = $ data [ $ column ] ? 'TRUE' : 'FALSE' ; elseif ( $ data [ $ column ] !== '' && $ data [ $ column ] !== NULL ) { $ placeholder [ $ column ] = "?" ; $ this -> placeholder_data [ ] = $ data [ $ column ] ; } } } $ placeholders [ ] = "(" . implode ( "," , $ placeholder ) . ")" ; } $ columns = "(" . implode ( "," , array_keys ( $ placeholder ) ) . ")" ; $ placeholders = implode ( "," , $ placeholders ) ; $ schema = '' ; $ returning = '' ; if ( $ this -> driver == 'pgsql' && $ this -> schema ) { if ( ! preg_match ( '/\./' , $ this -> table ) ) { $ schema = $ this -> schema ? $ this -> schema . '.' : '' ; } $ returning = $ returning_id ? 'RETURNING ' . $ this -> primaryKey : '' ; } $ this -> last_sql = $ this -> sql = "INSERT INTO {$schema}{$this->table} {$columns} VALUES {$placeholders} {$returning};" ; $ this -> fetch ( ) ; $ this -> data = $ this -> rows ; $ this -> reset ( ) ; if ( $ this -> tableOrig !== NULL ) { $ this -> table = $ this -> tableOrig ; } $ error = $ this -> error ( ) ; return $ error [ 'message' ] ? FALSE : TRUE ; } return FALSE ; }
inserta datos en la base de datos
@author Carlos Garcia
@param $datas Array
@param $returning_id Boolean
@return Boolean
inserta datos en la base de datos