Yii Framework Forum

Select data from one table in database1 and insert into another table in database2


(karthikeyansankar) #1

Guys please guide me to take a particular row of records from table1 on local database and insert into table1 on remote database.


(Alexander Makarov) #2
  1. select row from table 1.
  2. Insert row into table 2.

Check the official guide on how to do basic DB operations.


(karthikeyansankar) #3

Yes ,

My problem is Yii only accepts this kind of array

$values = array (
‘id’ => ‘7’,
‘user_type’ => ‘2’,
‘email_id’ => ‘staff@emperic.co’,
‘password’ => ‘8cb2237d0679ca88db6464eac60da96345513964’,
‘is_logged_in’ => ‘1’,
‘created_date’ => ‘2018-10-03 11:52:21’,
‘status’ => ‘1’
);
But I got my select result array like below yii is not accept this arrray as value

$values = Array (
[id] => 1
[user_type] => 1
[email_id] => fori@care.com
[password] => 8cb2237d0679ca88db6464eac60da96345513964
[is_logged_in] => 1
[created_date] => 2018-10-04 11:21:08
[status] => 1
);

Yii::app()->dbb->createCommand()->insert(‘user’,$values);


(Alexander Makarov) #4

Well, form new array from another array.


(Fsb) #5

I don’t see why not. You haven’t presented enough information for us to see what you’re doing wrong.

Btw: SHA-1(“12345”) = 8cb2237d0679ca88db6464eac60da96345513964

So don’t use that password. And SHA-1 hashing is not secure for password storage.


(karthikeyansankar) #6

I tried a lot but i can’t form an array like this using PHP.

$values = array (
‘id’ = ‘7’,
‘user_type’ = ‘2’,
‘email_id’ = ‘staff@emperic.co’,
‘password’ = ‘8cb2237d0679ca88db6464eac60da96345513964’,
‘is_logged_in’ = ‘1’,
‘created_date’ = ‘2018-10-03 11:52:21’,
‘status’ = ‘1’
);

is there any option to form an array using yii


(karthikeyansankar) #7

Thanks for your information Fsb.


(Fsb) #8

In PHP, = is the assignment operator, so the above code says to assign the value "7" to the string "id". You can’t assign to a string literal in PHP so it doesn’t compile. In PHP you assign to variables and to object properties.

Read about arrays here.

I guess what you really want is something like

$values = array(
    'id' => 7,
    'user_type' => 2,
    ...
);

Notice the => token separating key from value.


(karthikeyansankar) #9

Exactly Fsb is it possible to do in php using loop to create an array like this.

$values = array(
‘id’ => 7,
‘user_type’ => 2,

);


(Alexander Makarov) #10

Sure it’s possible: http://php.net/manual/en/langref.php


(karthikeyansankar) #11

Thank You Sam