Welcome Guest, Not a member yet? Register   Sign In
How to create database with post simultaneously
#1

(This post was last modified: 02-19-2022, 08:47 PM by luckmoshy.)

sounds dull but I want to check if DB exists to create a new one.

PHP Code:
public function create(){
//first check db if not create a new
$forge = \Config\Database::forge();
if (
$forge->createDatabase('my_db')) {
   
$forge->createTable('table_name');
}
else{
//if it is fire saving
   
$create = new mode();
  
$dat=model->save [
          
'post_one'-> $this->request->getVar('save');
        
'post_two'-> $this->request->getVar('save2');

];
}


But doesn't work how to do this by firstly stop check DB if exist to escape an error occurs?
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#2

PHP Code:
$forge->createDatabase('my_db'true);
// gives CREATE DATABASE IF NOT EXISTS `my_db`
// or will check if a database exists 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(02-20-2022, 01:40 AM)InsiteFX Wrote:
PHP Code:
$forge->createDatabase('my_db'true);
// gives CREATE DATABASE IF NOT EXISTS `my_db`
// or will check if a database exists 

thank you work fine
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply




Theme © iAndrew 2016 - Forum software by © MyBB