Ergebnis 1 bis 6 von 6

Thema: Zugriff auf externe Datenbank schlägt fehl.

  1. #1
    Contao-Nutzer Avatar von syntaxys
    Registriert seit
    05.05.2011.
    Ort
    Rheinzabern
    Beiträge
    50

    Standard Zugriff auf externe Datenbank schlägt fehl.

    Guten Morgen Forum,

    ich habe seit einiger Zeit ein funktionierendes Script im Einsatz, das mir Daten aus einer externen DB ausliest und verarbeitet. Seit dem Upgrade von 4.9 auf 4.13 funktioniert das nicht mehr:

    Code:
    [2022-08-08T04:46:35.956869+00:00] request.INFO: Matched route "tl_page.100". {"route":"tl_page.100","route_parameters":{"_token_check":true,"_controller":"Contao\\FrontendIndex::renderPage","_scope":"frontend","_locale":"de","_format":"html","_canonical_route":"tl_page.100","parameters":"","pageModel":{"Contao\\PageModel":[]},"_route":"tl_page.100","_route_object":{"Contao\\CoreBundle\\Routing\\Page\\PageRoute":[]}},"request_uri":"http://achim-c413.localhost/test.html","method":"GET"} []
    [2022-08-08T04:46:36.656087+00:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\UndefinedMethodError: "Attempted to call an undefined method named "fetchAll" of class "Doctrine\DBAL\Statement"." at /Volumes/DevZone/httpd/achim/httpd/c413/templates/achim/test/test.html5 line 48 {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\UndefinedMethodError(code: 0): Attempted to call an undefined method named \"fetchAll\" of class \"Doctrine\\DBAL\\Statement\". at /Volumes/DevZone/httpd/achim/httpd/c413/templates/achim/test/test.html5:48)"} []
    Nun versuche ich gerade das Script umzubauen:
    https://www.doctrine-project.org/pro...data-retrieval

    Und bekomme die gleiche Fehlermeldung mit fetchAllAssociative.

    Ich bin nicht so tief in der Entwicklung von Contao drin, scheinbar habe ich mal wieder etwas verpasst. Hat sich an der Methodik der DB-Zugriffe etwas geändert?

    Vielen Dank für Eure Hilfe!
    Achim
    „Arabica“ – ein One-Pager Theme für Contao 4.9: https://arabica.syntaxys.com/

  2. #2
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    30.320
    Partner-ID
    10107

    Standard

    Zitat Zitat von syntaxys Beitrag anzeigen
    Und bekomme die gleiche Fehlermeldung mit fetchAllAssociative.
    Nutze den Debug-Modus und poste den Stack Trace.
    » sponsor me via GitHub or PayPal or Revolut

  3. #3

  4. #4
    Contao-Nutzer Avatar von syntaxys
    Registriert seit
    05.05.2011.
    Ort
    Rheinzabern
    Beiträge
    50

    Standard

    Ich habe mir jetzt mal ganz basic in 4.9 und 4.13 ein Theme/Layout/Page aufgesetzt und folgendes probiert:

    Die Seite hat jeweils nur eine Überschrift und ein HTML-Inhaltselement mit {{file::Test/test.html5}}
    Das Template Test/test.html5 enthält in beiden Setups:

    PHP-Code:
    $ctn 'doctrine.dbal.live_achim_test_connection';
    $db 'dbname';

    $this->import('Database');
    $conn = \Contao\System::getContainer()->get($ctn);

        
    $headerName $conn->prepare("SELECT `".$db."`.`test`.`Bezeichnung` FROM `".$db."`.`test` WHERE `".$db."`.`test`.`id` = 5");
        
    $headerName->execute();
        
    $headerNameResult $headerName->fetchAllAssociative();

    print_r($headerNameResult); 
    Das ist die Ausgabe von Debug:

    Code:
    Symfony\Component\ErrorHandler\Error\
    UndefinedMethodError
    in templates/Test/test.html5 (line 10)
    $this->import('Database');
    $conn = \Contao\System::getContainer()->get($ctn);
        $headerName = $conn->prepare("SELECT `".$db."`.`test`.`Bezeichnung` FROM `".$db."`.`test` WHERE `".$db."`.`test`.`id` = 5"); 
        $headerName->execute();  
        $headerNameResult = $headerName->fetchAllAssociative();
    print_r($headerNameResult);
    Code:
    Symfony\Component\ErrorHandler\Error\UndefinedMethodError:
    Attempted to call an undefined method named "fetchAllAssociative" of class "Doctrine\DBAL\Statement".
    
      at templates/Test/test.html5:10
      at include()
         (vendor/contao/core-bundle/src/Resources/contao/library/Contao/InsertTags.php:1146)
      at Contao\InsertTags->executeReplace('<!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 --><!DOCTYPE html><html lang="de"><head>      <meta charset="UTF-8">    <title>Test DB - achim.lammerts.de</title>    <base href="http://achim-c413.localhost/">          <meta name="robots" content="index,follow">      <meta name="description" content="">      <meta name="generator" content="Contao Open Source CMS">                    [[TL_CSS_7ced653b04b53de535bdd50ab42882c8]]        [[TL_HEAD_7ced653b04b53de535bdd50ab42882c8]]  </head><body id="top" class="{{cache_mobiledetectioncss|attr}}">          <div id="wrapper">                                        <div id="container">                      <main id="main">              <div class="inside">                <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->  <div class="mod_article block" id="article-384">              <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><h2 class="ce_headline">  Test DB</h2><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->{{file::Test/test.html5}}<!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->          </div><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->              </div>                          </main>                                                                                  </div>                                    </div>        [[TL_BODY_7ced653b04b53de535bdd50ab42882c8]]  <script type="application/ld+json">[    {        "@context": "https:\\/\\/schema.org",        "@graph": [            {                "@type": "WebPage"            }        ]    },    {        "@context": "https:\\/\\/schema.contao.org",        "@graph": [            {                "@type": "Page",                "fePreview": false,                "groups": [],                "noSearch": false,                "pageId": 130,                "protected": false,                "title": "Test DB"            }        ]    }]</script></body></html><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 -->', true)
         (vendor/contao/core-bundle/src/Resources/contao/library/Contao/InsertTags.php:100)
      at Contao\InsertTags->replaceInternal('<!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 --><!DOCTYPE html><html lang="de"><head>      <meta charset="UTF-8">    <title>Test DB - achim.lammerts.de</title>    <base href="http://achim-c413.localhost/">          <meta name="robots" content="index,follow">      <meta name="description" content="">      <meta name="generator" content="Contao Open Source CMS">                    [[TL_CSS_7ced653b04b53de535bdd50ab42882c8]]        [[TL_HEAD_7ced653b04b53de535bdd50ab42882c8]]  </head><body id="top" class="{{cache_mobiledetectioncss}}">          <div id="wrapper">                                        <div id="container">                      <main id="main">              <div class="inside">                <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->  <div class="mod_article block" id="article-384">              <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><h2 class="ce_headline">  Test DB</h2><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->{{file::Test/test.html5}}<!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->          </div><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->              </div>                          </main>                                                                                  </div>                                    </div>        [[TL_BODY_7ced653b04b53de535bdd50ab42882c8]]  <script type="application/ld+json">[    {        "@context": "https:\\/\\/schema.org",        "@graph": [            {                "@type": "WebPage"            }        ]    },    {        "@context": "https:\\/\\/schema.contao.org",        "@graph": [            {                "@type": "Page",                "fePreview": false,                "groups": [],                "noSearch": false,                "pageId": 130,                "protected": false,                "title": "Test DB"            }        ]    }]</script></body></html><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 -->', true)
         (vendor/contao/core-bundle/src/InsertTag/InsertTagParser.php:73)
      at Contao\CoreBundle\InsertTag\InsertTagParser->callLegacyClass('<!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 --><!DOCTYPE html><html lang="de"><head>      <meta charset="UTF-8">    <title>Test DB - achim.lammerts.de</title>    <base href="http://achim-c413.localhost/">          <meta name="robots" content="index,follow">      <meta name="description" content="">      <meta name="generator" content="Contao Open Source CMS">                    [[TL_CSS_7ced653b04b53de535bdd50ab42882c8]]        [[TL_HEAD_7ced653b04b53de535bdd50ab42882c8]]  </head><body id="top" class="{{cache_mobiledetectioncss}}">          <div id="wrapper">                                        <div id="container">                      <main id="main">              <div class="inside">                <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->  <div class="mod_article block" id="article-384">              <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><h2 class="ce_headline">  Test DB</h2><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->{{file::Test/test.html5}}<!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->          </div><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->              </div>                          </main>                                                                                  </div>                                    </div>        [[TL_BODY_7ced653b04b53de535bdd50ab42882c8]]  <script type="application/ld+json">[    {        "@context": "https:\\/\\/schema.org",        "@graph": [            {                "@type": "WebPage"            }        ]    },    {        "@context": "https:\\/\\/schema.contao.org",        "@graph": [            {                "@type": "Page",                "fePreview": false,                "groups": [],                "noSearch": false,                "pageId": 130,                "protected": false,                "title": "Test DB"            }        ]    }]</script></body></html><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 -->', true)
         (vendor/contao/core-bundle/src/InsertTag/InsertTagParser.php:37)
      at Contao\CoreBundle\InsertTag\InsertTagParser->replaceChunked('<!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 --><!DOCTYPE html><html lang="de"><head>      <meta charset="UTF-8">    <title>Test DB - achim.lammerts.de</title>    <base href="http://achim-c413.localhost/">          <meta name="robots" content="index,follow">      <meta name="description" content="">      <meta name="generator" content="Contao Open Source CMS">                    [[TL_CSS_7ced653b04b53de535bdd50ab42882c8]]        [[TL_HEAD_7ced653b04b53de535bdd50ab42882c8]]  </head><body id="top" class="{{cache_mobiledetectioncss}}">          <div id="wrapper">                                        <div id="container">                      <main id="main">              <div class="inside">                <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->  <div class="mod_article block" id="article-384">              <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><h2 class="ce_headline">  Test DB</h2><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->{{file::Test/test.html5}}<!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->          </div><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->              </div>                          </main>                                                                                  </div>                                    </div>        [[TL_BODY_7ced653b04b53de535bdd50ab42882c8]]  <script type="application/ld+json">[    {        "@context": "https:\\/\\/schema.org",        "@graph": [            {                "@type": "WebPage"            }        ]    },    {        "@context": "https:\\/\\/schema.contao.org",        "@graph": [            {                "@type": "Page",                "fePreview": false,                "groups": [],                "noSearch": false,                "pageId": 130,                "protected": false,                "title": "Test DB"            }        ]    }]</script></body></html><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 -->')
         (vendor/contao/core-bundle/src/InsertTag/InsertTagParser.php:32)
      at Contao\CoreBundle\InsertTag\InsertTagParser->replace('<!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 --><!DOCTYPE html><html lang="de"><head>      <meta charset="UTF-8">    <title>Test DB - achim.lammerts.de</title>    <base href="http://achim-c413.localhost/">          <meta name="robots" content="index,follow">      <meta name="description" content="">      <meta name="generator" content="Contao Open Source CMS">                    [[TL_CSS_7ced653b04b53de535bdd50ab42882c8]]        [[TL_HEAD_7ced653b04b53de535bdd50ab42882c8]]  </head><body id="top" class="{{cache_mobiledetectioncss}}">          <div id="wrapper">                                        <div id="container">                      <main id="main">              <div class="inside">                <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->  <div class="mod_article block" id="article-384">              <!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><h2 class="ce_headline">  Test DB</h2><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_headline.html5 --><!-- TEMPLATE START: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->{{file::Test/test.html5}}<!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/elements/ce_html.html5 -->          </div><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/modules/mod_article.html5 -->              </div>                          </main>                                                                                  </div>                                    </div>        [[TL_BODY_7ced653b04b53de535bdd50ab42882c8]]  <script type="application/ld+json">[    {        "@context": "https:\\/\\/schema.org",        "@graph": [            {                "@type": "WebPage"            }        ]    },    {        "@context": "https:\\/\\/schema.contao.org",        "@graph": [            {                "@type": "Page",                "fePreview": false,                "groups": [],                "noSearch": false,                "pageId": 130,                "protected": false,                "title": "Test DB"            }        ]    }]</script></body></html><!-- TEMPLATE END: vendor/contao/core-bundle/src/Resources/contao/templates/frontend/fe_page.html5 -->')
         (vendor/contao/core-bundle/src/Resources/contao/classes/FrontendTemplate.php:128)
      at Contao\FrontendTemplate->compile()
         (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Template.php:322)
      at Contao\Template->getResponse()
         (vendor/contao/core-bundle/src/Resources/contao/classes/FrontendTemplate.php:85)
      at Contao\FrontendTemplate->getResponse(true)
         (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:62)
      at Contao\PageRegular->getResponse(object(PageModel), true)
         (vendor/contao/core-bundle/src/Resources/contao/controllers/FrontendIndex.php:320)
      at Contao\FrontendIndex->renderPage(object(PageModel))
         (vendor/symfony/http-kernel/HttpKernel.php:152)
      at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
         (vendor/symfony/http-kernel/HttpKernel.php:74)
      at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
         (vendor/symfony/http-kernel/Kernel.php:202)
      at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
         (web/index.php:44)
    In 4.9 funktioniert das, in 4.13 nicht mehr.

    Vielen Dank für Eure Hilfe!
    LG/A
    „Arabica“ – ein One-Pager Theme für Contao 4.9: https://arabica.syntaxys.com/

  5. #5
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    30.320
    Partner-ID
    10107

    Standard

    Ändere
    PHP-Code:
        $headerName $conn->prepare("SELECT `".$db."`.`test`.`Bezeichnung` FROM `".$db."`.`test` WHERE `".$db."`.`test`.`id` = 5");
        
    $headerName->execute();
        
    $headerNameResult $headerName->fetchAllAssociative(); 
    auf
    PHP-Code:
        $headerNameResult $conn->fetchAllAssociative("SELECT `".$db."`.`test`.`Bezeichnung` FROM `".$db."`.`test` WHERE `".$db."`.`test`.`id` = 5"); 
    » sponsor me via GitHub or PayPal or Revolut

  6. #6
    Contao-Nutzer Avatar von syntaxys
    Registriert seit
    05.05.2011.
    Ort
    Rheinzabern
    Beiträge
    50

    Standard

    Man sollte sich halt die Doku nicht vor dem ersten Kaffee ansehen ????
    https://www.doctrine-project.org/pro...rieval#prepare

    Es funktioniert, wie beschrieben!

    PHP-Code:
    $headerName $conn->prepare($arrQuery['headerName']);
    $headerName->bindValue('header'$arrSession['key1']['key2']);
    $resultSet $headerName->executeQuery();
    $headerNameResult $resultSet->fetchAllAssociative(); 
    Danke für die Hilfe!
    „Arabica“ – ein One-Pager Theme für Contao 4.9: https://arabica.syntaxys.com/

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •