Run php script for 1 site (on his database) in multisite

Hi,

I have some sites in multisite, same code for all of the sites. I want to create a page programmatically with a script php. It worked when i use 1 core per site, but in multisite its not working, databases problems.

The script :

<?php

  use DrupalCoreDrupalKernel;
  use SymfonyComponentHttpFoundationRequest;

  $autoloader = require_once 'autoload.php';

  $kernel = new DrupalKernel('prod', $autoloader);

  $request = Request::createFromGlobals();
  $response = $kernel->handle($request);
   $response->send();

  use DrupalnodeEntityNode;
  use DrupalfileEntityFile;


  $node = Node::create([
  'type' => 'page',
  'langcode' => 'en',
  'created' => REQUEST_TIME,
  'changed' => REQUEST_TIME,
  'uid' => 1,
  'title' => 'Ma page!',
  'body' => [
    'summary' => '',
    'value' => '<p>Bla bla bla bla.</p>',
    'format' => 'full_html',
  ],
]);
  $node->save();
  

The error after running with php create_page.php :

DrupalCoreDatabaseConnectionNotDefinedException: The specified database connection is not defined: default in /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Core/Database/Database.php on line 361 #0 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Core/Database/Database.php(166): DrupalCoreDatabaseDatabase::openConnection(‘default’, ‘default’)
#1 [internal function]: DrupalCoreDatabaseDatabase::getConnection(‘default’)
#2 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(79): call_user_func_array(‘DrupalCoreDat…’, Array)
#3 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Component/DependencyInjection/Container.php(177): DrupalComponentDependencyInjectionPhpArrayContainer->createService(Array, ‘database’)
#4 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(264): DrupalComponentDependencyInjectionContainer->get(‘database’, 1)
#5 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php(62): DrupalComponentDependencyInjectionPhpArrayContainer->resolveServicesAndParameters(Array)
#6 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Component/DependencyInjection/Container.php(177): DrupalComponentDependencyInjectionPhpArrayContainer->createService(Array, ‘cache.container’)
#7 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Core/DrupalKernel.php(508): DrupalComponentDependencyInjectionContainer->get(‘cache.container’)
#8 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Core/DrupalKernel.php(860): DrupalCoreDrupalKernel->getCachedContainerDefinition()
#9 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Core/DrupalKernel.php(461): DrupalCoreDrupalKernel->initializeContainer()
#10 /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Core/DrupalKernel.php(651): DrupalCoreDrupalKernel->boot()
#11 /var/www/html/drupalOctobre/drupalOct/sites/multisite/creer_page.php(11): DrupalCoreDrupalKernel->handle(Object(SymfonyComponentHttpFoundationRequest))
#12 {main}
DrupalCoreDatabaseConnectionNotDefinedException: The specified database connection is not defined: default in DrupalCoreDatabaseDatabase::openConnection() (line 361 of /var/www/html/drupalOctobre/drupalOct/core/lib/Drupal/Core/Database/Database.php).

Any idea ?

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/4/feed