Multiple Insert

Hi all,

I'm new to Phalcon, I read the doc but still can't figure this out.

What would be the best way to save large amount of rows in one insert ?

II tried to save a single row and it's working fine. Example: php $phql = "INSERT INTO Person (first_name, last_name, middle_name) VALUES (:first_name:, :last_name:, :middle_name:)"; $status = $this->modelsManager->executeQuery($phql, array( 'first_name' => $friend['first_name'], 'last_name' => $friend['last_name'], 'middle_name' => $friend['last_name'] ));

Is there a way to save a multidimentional array using this method 'executeQuery' ?

Example: What if my variable $friends is something like php $friends = array ($friend, $friend, $friend);?>

Thanks.

Insert multiple rows by one INSERT? You can use transactions for paste many rows at one time, however I don't know is PHQL allows to do that or not, because I'm a newbie in Phalcon too.



2.7k

I'm not sure I want to sure transactions here but I'll check it out. Thank you

This is a feature specific to a RDBMS and Phalcon does not support it through PHQL.

You can always do a for - next loop and insert each record in turn or use raw SQL to do that.

There has been another discussion or an issue in Github regarding this and we decided not to allow mass row insert purely from a security point of view. RDBMSs (like MySQL) offers tools to bulk insert rows and with the use of transactions or raw SQL you can achieve what you are looking for.



2.7k

Yeah that's what I ended up using raw sql. Do you have the link to the discussion ? just curious.

Thanks Nikolaos.