I am using laravel with mongodb, This is my update query
$user = User::where('_id', '=', $row)
->update(['userid' => $userid,
'username' => $username,
'email' => $emailid,
'mobileno' => $mobile,
'manager_mail' => $manager_mail,
'roleid' => $role]);
While inserting role id is inserted as a string, how can i insert as a integer? please help
If you know $roleid will always be a numeric value, you can use intval in php when passing $roleid.
E.g. intval($role)
Read about it here: http://php.net/manual/en/function.intval.php
Related
I am using Laravel with mongodb(Jenssegers), i have array data like following,
$insert[] = ['sub_id'=>$loggedin,
'userid' => $row->userid,
'username' => $row->username,
'email' => $row->email,
'mobileno' => $row->mobileno,
'manager_mail' => $row->manager_mail,
'roleid' => $userrole->roleid];
my insert query is,
$user->save($insert);
But its not working, please suggest any solution?
You need to use create() or insert() methods:
User::create($insert);
Or:
User::insert($insert);
Or:
DB::table('table_name')->insert($insert);
Eloquent save method accept 1D array. But you provided 2D. Please try following code:
$insert = ['sub_id'=>$loggedin,
'userid' => $row->userid,
'username' => $row->username,
'email' => $row->email,
'mobileno' => $row->mobileno,
'manager_mail' => $row->manager_mail,
'roleid' => $userrole->roleid];
$user->save($insert);
I'm new to Fuel...
got my script inserting a record using the following code:
$address = Model_Address::forge(array(
'street1' => $step1_data['street1'],
'street2' => $step1_data['street2'],
'suburb' => $step1_data['street2'],
'city' => $step1_data['city'],
'region' => $step1_data['region'],
'country' => $step1_data['country'],
'postcode' => $step1_data['postcode'],
));
$address->save();
I think I should be able to get the insert id via $address->id but it's empty.
I'm not sure what I'm doing wrong?
We are using pg_swl not sure if that makes any difference.
Saving model data fails to insert any of array datatype fields. Data array to store.
array(
'catalog_id' => '14',
'foreign_model[1]' => 'Catalog',
'foreign_model_key[1]' => (int) 3,
'foreign_key[1]' => '4',
'name' => 'T580.26',
'integer[1]' => '44000',
'integer[2]' => '3'
'amount[1]' => '140000';
)
Stored are only catalog_id and name values.
What I have tried so far.
$this->Catalog->save($data, array_keys($data));
and
$this->Catalog->whitelist = array_keys($data);
$this->Catalog->save($data);
Any ideas what else can be done?
Array is a data type that is not supported by CakePHP's ORM.
See https://github.com/cakephp/cakephp/blob/master/lib/Cake/Model/Datasource/Database/Postgres.php#L53
You can extend the Postgres datasource and add it.
I have something like this:
$data = array('username' => 'John', 'password' => 'john123');
$table = new Zend_Db_Table('users');
$table->insert($data);
But I want it to include a hashing function to the password, so the sql is something like this:
INSERT INTO `users` (`username`, `password`) VALUES ('John', PASSWORD('john123'));
How can I do that, elegantly?
$data = array('username' => 'John', 'password' => new Zend_Db_Expr('SHA1(john123)');
When i use the Zend_Form_Element_Select elements with multioptions i get this error when i pass the selected value to Zend_DB_Table to insert into the db
Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts_status ' in 'field list'
I have extracted some code snippets that i believe will go a long way into illustrating my problem.The accounts_status field DOES exist in my table
On my form construct have added the select element and options (I have left out the other elements)
$optionsstatus = array(
'active' => 'active',
'pending' => 'pending'
);
$optionsrole = array(
'guest' => 'guest',
'user' => 'user',
'writer' => 'writer',
'admin' => 'admin'
);
$status = new Zend_Form_Element_Select('accounts_status');
$status->setLabel('Status')
->setRequired(true)
->addMultiOptions($optionsstatus);
$role = new Zend_Form_Element_Select('accounts_role');
$role->setLabel('Role')
->setRequired(true)
->addMultiOptions($optionsrole);
I use the Zend_DB_table to insert the post values from my controller
public function addaccount($username, $fullname, $email,
$password,$status,$roles,$comments)
{
$data = array(
'accounts_username' => $username,
'accounts_fullname' => $fullname,
'accounts_email' => $email,
'accounts_password' => $password,
'accounts_status ' => $status,
'accounts_roles' => $roles,
'accounts_comments ' => $comments,
);
$this->insert($data);
}
In my controller i get the post values and send them to my model
$username = $form->getValue('accounts_username');
$fullname = $form->getValue('accounts_fullname');
$email = $form->getValue('accounts_email');
$password = $form->getValue('accounts_password');
$status = $form->getValue('accounts_status');
$roles = $form->getValue('accounts_roles');
$comments = $form->getValue('accounts_comments');
$accounts = new Model_DbTable_Account();
$accounts->addaccount($username, $fullname,$email,
$password,$status,$roles,$comments);
This approach works for me except when am dealing with the Zend_Form_Element_Select elements.Am just wondering if there is a specific way of dealing with this select elements when it comes to CRUD operations.
Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts_status ' in 'field list'
Maybe I'm crazy, but looks to me like there's an extra space on that end of that 'accounts_status ' field name.