/** * Method to insert data to the database * * NOTE: This function may return Boolean FALSE, * but may also return a non-Boolean value which evaluates to FALSE. * * @since 1.0.0 * @access public * * @param array $data Data to insert (should be [db_column => value]) * * @return mixed Insert ID on success or FALSE on failure **/ public function insert($data) { // Initialize PDO object $this->queryInit(); // Get the columns and values to insert $columns = array_keys($data); $values = array_values($data); // Build insert query $query = sprintf("INSERT INTO %s (%s) VALUES (%s)", $this->table, implode(', ', $columns), rtrim(str_repeat('?,', count($values)), ',')); // Prepare and execute the insert query $insert = $this->pdo->prepare($query); $flag = $insert->execute($values); return $flag ? intval($this->pdo->lastInsertId()) : false; }