Looking for database insert example
To inject the database service add/alter the following methods in your controller class:

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Symfony\Component\DependencyInjection\ContainerInterface;

class PetmdController extends ControllerBase {

  protected $database;

  public function __construct(Connection $database) {
    $this-&gt;database = $database;
  }

  public static function create(ContainerInterface $container) {
    return new static(
      $container-&gt;get('database')
    );
  }

  public function foo() {
    $this-&gt;database-&gt;insert(...)-&gt;fields(...)-&gt;execute();
  }
}