CodeIgniter 4
Revisão de 22h14min de 12 de setembro de 2021 por Renefgj (discussão | contribs) (→Contagem de registros)
Í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();