Question

I can't find the way connect multiple db and chain sql query,

How to use raw mysql syntax?

$id = DB::connection('mysql1')->select(DB::raw('INSERT INTO article_category (name) VALUES (:name)'), array(
    'name' => $name
));  // did I do something wrong this not work..

How to use laravel method?

$id = DB::connection('mysql1')->table('article_category')->insertGetId(
    array(
        'name' => $name
    )
);
Was it helpful?

Solution

You do raw this way:

DB::connection('mysql1')
    ->statement(
         DB::raw('insert into article_category (name) values (?)'),
         array($name)
    );

To get the Id after an insert this is a way:

Create a model for your table:

class Post extends Eloquent {}

And create a record on your table selecting a particular connection connection:

$post = Post::on('connectionName')->create($arrayOfvalues);

echo $post->id;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top