ZenDB error (3.65 install)

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 26, 2024   (RSS)

By KennyH - February 23, 2024

I have a sitemap generated by CMSB and it is giving me this error after a 3.65 upgrade 

#15429 - Typed static property Itools\ZenDB\DB::$lastInstance must not be accessed before initialization
/home/xxxxxx/domains/domain.com/public_html/sitemap.php on line 82
https://www.domain.com/sitemap.php?xml

My sitemap code looks like this:

<?php
  header('Content-type: application/xml');
  require_once('webadmin/lib/viewer_functions.php');

  $domain = "https://" . $_SERVER['HTTP_HOST'];

  $output = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
  echo $output;

   list($permalinksRecords, $permalinksMetaData) = getRecords(array(
    'tableName'   => '_permalinks',
    'loadUploads' => false,
    'allowSearch' => false,
    "where" => "!old",
  ));

  list($faqRecords, $faqMetaData) = getRecords(array(
    'tableName'   => 'faq',
    'limit'       => '1',
    'loadUploads' => false,
    'allowSearch' => false,
  ));

  list($event_calendarRecords, $event_calendarMetaData) = getRecords(array(
    'tableName'   => 'event_calendar',
    'limit'       => '1',
    'loadUploads' => false,
    'allowSearch' => false,
  ));

  list($article_postsRecords, $article_postsMetaData) = getRecords(array(
    'tableName'   => 'article_posts',
    'limit'       => '1',
    'loadUploads' => false,
    'allowSearch' => false,
  ));

	list($employmentRecords, $employmentMetaData) = getRecords(array(
    'tableName'   => 'employment',
    'where'       => '!hide_content',
    'limit'       => '1',
    'loadUploads' => false,
    'allowSearch' => false,
	));

?>
<?php $pages = [
  '/',
	'/about/',
  '/contact/',
  '/products/',
];

if ($faqRecords) {
  $pages[] = '/faq/';
}

if ($event_calendarRecords) {
  $pages[] = '/events/';
}

if ($employmentRecords) {
  $pages[] = '/employment/';
}

if ($article_postsRecords) {
  $pages[] = '/articles/';
}

foreach ($pages as $page) {
  echo '<url>
	  <loc>' . $domain . $page . '</loc>
	  <lastmod>' . date("Y-m-d") . '</lastmod>
	  <changefreq>weekly</changefreq> 
	  <priority>0.5</priority>
	</url>';
}

foreach ($permalinksRecords as $record) {
  if($record['tableName'] && $record['recordNum']){
    $linkedRecord = mysql_get($record['tableName'], $record['recordNum']);
  }

  if ($record['tableName'] === 'employment' && @$linkedRecord['hide_content']) {
    continue;
  }

  if (!$record['old'] && !@$linkedRecord['hidden']) {
    echo '<url>
      <loc>' . $domain . '/' . $record['permalink'] . '/' . '</loc>
      <lastmod>' . date('Y-m-d', strtotime($record['updatedDate'])) . '</lastmod>
      <changefreq>weekly</changefreq>
      <priority>0.5</priority>
    </url>';
  }
}
?>
</urlset>

Specifically, line 82 in my files says: $linkedRecord = mysql_get($record['tableName'], $record['recordNum']);

By Dave - February 23, 2024

Hi Kenny, 

Can you send in a support request for that one (or send me the server details) and I can take a look.

Usually, that error indicates a MySQL error somewhere, but I'll take a look to find out and improve the error reporting on it.

Thanks!

Dave Edis - Senior Developer
interactivetools.com

By Dave - February 23, 2024

Hi Kenny, 

Actually, here's a quick fix you can try.  In /cmsb/lib/ZenDB/DBUtilsTrait.php search for getLastEmulatedQuery

and replace this: 

    public static function getLastEmulatedQuery(): string {
        $dbPrepare = self::$lastInstance->prepare;

with this: 

    public static function getLastEmulatedQuery(): string {
        $dbPrepare = self::$lastInstance->prepare ?? null;

Let me know if that helps.

If there's still an error feel free to send in server details and we can investigate.

Dave Edis - Senior Developer
interactivetools.com