user167850
user167850

Reputation: 497

Cakephp insert sql statement

I'd like to insert data into a mysql table using 'the cakephp way'.

I have a multi-stage program that stores data to a session, and toward the end of the program I'd like to write the session data to the database. I could do this using a standard sql insert statement but would like to know how this should be done using cakephp. (Most of the cakephp doc discusses sending data from a webform, and I'd like to manually submit session data.)

Should I manually format the session data in this format and then send this to the model? And if so, is there a helper function for this?

Array
(
    [ModelName] => Array
        (
            [fieldname1] => 'value'
            [fieldname2] => 'value'
        )
)

Upvotes: 1

Views: 4598

Answers (1)

JJJ
JJJ

Reputation: 33163

Yes, that's the way to do it. There's really no need for a helper function, just use the ones you normally would.

$name = 'Foo';
$city = 'Bar';

$this->ModelName->save( 
    array(
        'name' => $name,
        'city' => $city
    )
);

Upvotes: 2

Related Questions