How to insert data into multiple tables using codeIgniter - codeigniter

I am working on MVC Framework (codeIgniter)
tbl_emp, tbl_address, tbl_salary
I created 3 tables in one database, and now i want to pass the data into 3 tables by using single query using INSERT . Please help me out with this query...

You can't do it in one statement but you can do it in transaction :
$this->db->trans_start();
$this->db->query('INSERT QUERY...');
$this->db->query('ANOTHER INSERT QUERY...');
$this->db->query('AND YET ANOTHER INSERT QUERY...');
$this->db->trans_complete();

Related

Laravel how to move data from table to another

Is there any simple way to move data from table to table using the id? I want to get all the info inside the first table using the id, insert it to another table, and then delete it from current one using Laravel.
Assuming both tables have the same schema you can do:
TableB::create(TableA::find($id));

oracle synchronize 2 tables

I have the following scenario and need to solve it in ORACLE:
Table A is on a DB-server
Table B is on a different server
Table A will be populated with data.
Whenever something is inserted to Table A, i want to copy it to Table B.
Table B nearly has similar columns, but sometimes I just want to get
the content from 2 columns from tableA and concatenate it and save it to
Table B.
I am not very familiar with ORACLE, but after researching on GOOGLE
some say that you can do it with TRIGGERS or VIEWS, how would you do it?
So in general, there is a table which will be populated and its content
should be copien to a different table.
This is the solution I came up so far
create public database link
other_db
connect to
user
identified by
pw
using 'tns-entry';
CREATE TRIGGER modify_remote_my_table
AFTER INSERT ON my_table
BEGIN INSERT INTO ....?
END;
/
How can I select the latest row that was inserted?
If the databases of these two tables are in two different servers, then you will need a database link (db-link) to be created in Table A schema so that it can access(read/write) the Table B data using db-link.
Step 1: Create a database link in Table A server db pointing to Table B server DB
Step 2: Create a trigger for Table A, which helps in inserting data to the table B using database link. You can customize ( concatenate the values) inside the trigger before inserting it into table B.
This link should help you
http://searchoracle.techtarget.com/tip/How-to-create-a-database-link-in-Oracle
Yes you can do this with triggers. But there may be a few disadvantages.
What if database B is not available? -> Exception handling in you trigger.
What if database B was not available for 2h? You inserted data into database A which is now missing in database B. -> Do crazy things with temporarily inserting it into a cache table in database A.
Performance. Well, the performance for inserting a lot of data will be ugly. Each time you insert data, Oracle will start the PL/SQL engine to insert the data into the remote database.
Maybe you could think about using MViews (Materialized Views) to replicate the data via database link. Later you can build your queries so that they access tables from database B and add the required data from database A by joining the MViews.
You can also use fast refresh to replicate the data (almost) realtime.
From perspective of an Oracle Database Admin this would make a lot more sense than the trigger approach.
try this code
database links are considered rather insecure and oracle own options are having licences associated these days, some of the other options are deprecated as well.
https://gist.github.com/anonymous/e3051239ba401e416565cdd912e0de8c
uses ora_rowscn to sync tables across two different oracle databases.

get values from another table on a trigger

So, i am a begginer on ORACLE and realy would apreciate your help.
I have 3 tables, EMPLOEES, PERSONAL_DATA and RECORDS. I want to create an UPDATE TRIGGER that when fires takes the old values of EMPLOOES finds the personal data of that updating emplooe on the PERSONAL_DATA table with the OLD id and insert all of that data( the OLD of EMPLOOES and the one fetched from PERSONAL_DATA) into the RECORDS table. I been triying to use the SELECT sentence to fetch information from the table PERSONAL_DATA, but the compiler throws me an error.

Data insertion issue using cakephp 3.2 to oracle 11g tables

I am just trying to build a simple crud application using cakephp and oracle. But when i am trying to add a new data from my add.ctp its return with this error. can anyone help. Errors are below.
ORA-01400: cannot insert NULL into ("HR"."EMP"."EMP_ID")
CakeDC\OracleDriver\Database\OCI8\OCI8Exception
BTW here 'EMP_ID' is primary key of 'EMP' table and i have also created sequence.
You should try to create all tables strctures using cakephp migrations.
The reason of that - datasource when create table dditionally create not only sequence, but also a triger, to fill id field. Also driver written in way to follow cakephp table field naming conventions. So you can just take EMP schema and get everything work.
Options are: create all tables using migrations from cakephp side, or write trigger that will fill id fields manual on oracle side.

updating data from one to table to another table which are in two different schema

I got two schema A and B. In A there is a table 'company' and in B there is a table 'newcompany'. Now I need all the data which is residing on A.company to be updated on B.newcompany whenever there is some data updation on A.company.
Please help me out with a query or some function which implements this functionality.
You could give grants to the user and simply access the table as B.newcompany inside an onupdate trigger for the A.company table.

Resources