Mudanças entre as edições de "CodeIgniter 4"
Ir para navegação
Ir para pesquisar
| Linha 71: | Linha 71: | ||
$builder->insert($data); | $builder->insert($data); | ||
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date') | // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date') | ||
| + | |||
| + | == Update == | ||
| + | $RDFLiteral->set('n_name', $texto, false); | ||
| + | $RDFLiteral->where('id_sc',$id)->replace($data); | ||
Edição das 02h39min de 4 de novembro de 2021
Índice
Instalação
Configuração Inicial
Alterar o nome do arquivo "env" para ".env" Dentro do arquivo, alterar o tipo:
CI_ENVIRONMENT = production
ou
CI_ENVIRONMENT = developent
Configure a conexão com o banco de dados database.default.hostname = MariaDB database.default.database = cip database.default.username = root database.default.password = root database.default.DBDriver = MySQLi database.default.DBPrefix =
SPARK
php spark migrate
Iniciar servidor local do Spark
php spark serve
Criar um arquivo de migração de banco de dados
php spark make:migration __nome_da_classe_(nao repetir)__
Estrutura do arquivo
public function up()
{
//
$this->forge->addField([
'id_p' => [ 'type' => 'INT', 'auto_increment' => true ],
'p_ip' => [ 'type' => 'VARCHAR', 'constraint' => '20' ],
'p_family' => [ 'type' => 'VARCHAR', 'constraint' => '20' ],
'p_title' => [ 'type' => 'TEXT' ],
'created_at datetime default current_timestamp',
'updated_at datetime default current_timestamp on update current_timestamp'
]);
$this->forge->addKey('id_p', true);
$this->forge->createTable('patents');
}
Criar um model
php spark make:model Patents
Banco de dados
Contagem de registros
$dt = $this->where('c_th',$id)->get();
$count = $dt->resultID->num_rows;
Group By
$this->select("count(*) as total, rl_lang");
$this->join('th_concept_term','ct_term = id_rl');
$this->groupBy('rl_lang');
$dt = $this->where('ct_th',$id)->findAll();
Mostrar Query de Consulta
$this->db->getLastQuery();
Mostrar Resultado de uma Query
$dt = (array)$this->db->query($sql)->getResult();
Inserindo dados (APPEND)
$data = [
'title' => 'My title',
'name' => 'My Name',
'date' => 'My date',
];
$builder->insert($data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
Update
$RDFLiteral->set('n_name', $texto, false);
$RDFLiteral->where('id_sc',$id)->replace($data);