miconda / yourls

Extensions for yourls http link shortner
13 stars 18 forks source link

Class 'YOURLS\\Database\\YDB' does not have a method 'get_results' #2

Closed profcaju closed 2 years ago

profcaju commented 2 years ago

Hello.

I used to use a lot this extension in my old server (Ubuntu 16.04 with Yourls 1.7).

But, after upgrading to Ubuntu 20.04 and Yourls 1.9, I get this error with this extension whenever I try to see the popular linkks

[Tue May 03 19:24:18.896599 2022] [php7:error] [pid 29821] [client 172.71.10.9:48744] PHP Fatal error:  Uncaught BadMethodCallException: Class 'YOURLS\\Database\\YDB' does not have a method 'get_results' in /home/ubuntu/www/includes/vendor/aura/sql/src/AbstractExtendedPdo.php:113
Stack trace:
#0 /home/ubuntu/www/user/plugins/popular-clicks/plugin.php(34): Aura\\Sql\\AbstractExtendedPdo->__call()
#1 /home/ubuntu/www/user/plugins/popular-clicks/plugin.php(50): show_top()
#2 /home/ubuntu/www/includes/functions-plugins.php(819): popularclicks_do_page()
#3 /home/ubuntu/www/admin/plugins.php(8): yourls_plugin_admin_page()
#4 {main}
  thrown in /home/ubuntu/www/includes/vendor/aura/sql/src/AbstractExtendedPdo.php on line 113, referer: http://xxx.xx/admin/plugins.php?page=popular_clicks

Is there some bug with this extension an Yourls newest version? Or is something I am missing in my installation?

Kind regards,

miconda commented 2 years ago

I haven't used this extension for long time, it seems that the DB api changed and this extension has to be updated:

Not sure when I will get time to it, might not be something complex to code in php, the code is rather minimal, but I don't have a system running this extension at this moment where I could test new code.

profcaju commented 2 years ago

Oh, good!!! I just managed to make it work after reading the link you've sent me :D

Changing lines 34 to 43 from your currrent code to:

        $sql = "SELECT a.shorturl AS shorturl, count(*) AS clicks, b.url AS longurl FROM `$table_log` a, `$table_url` b WHERE a.shorturl=b.keyword AND DATE_SUB(NOW(), INTERVAL $numdays DAY)<a.click_time GROUP BY a.shorturl ORDER BY count(*) DESC LIMIT $numrows";
        $query = $ydb->fetchAll($sql);

        if ($query) {
            foreach( $query as $query_result ) {
                $outdata .= '<tr><td>' . $query_result['clicks'] . '</td><td><a href="' .$base .'/' . $query_result['shorturl'] .'+" target="blank">'
                    . $query_result['shorturl'] .'</a>'
                    . '</td><td><a href="' . $query_result['longurl'] .'" target="blank">'
                    . $query_result['longurl'] . '</td></tr>';
            }
        }

Thanks for your help 🤗

Akila3 commented 2 years ago

Oh, good!!! I just managed to make it work after reading the link you've sent me :D

Changing lines 34 to 43 from your currrent code to:

      $sql = "SELECT a.shorturl AS shorturl, count(*) AS clicks, b.url AS longurl FROM `$table_log` a, `$table_url` b WHERE a.shorturl=b.keyword AND DATE_SUB(NOW(), INTERVAL $numdays DAY)<a.click_time GROUP BY a.shorturl ORDER BY count(*) DESC LIMIT $numrows";
      $query = $ydb->fetchAll($sql);

      if ($query) {
          foreach( $query as $query_result ) {
                $outdata .= '<tr><td>' . $query_result['clicks'] . '</td><td><a href="' .$base .'/' . $query_result['shorturl'] .'+" target="blank">'
                    . $query_result['shorturl'] .'</a>'
                  . '</td><td><a href="' . $query_result['longurl'] .'" target="blank">'
                  . $query_result['longurl'] . '</td></tr>';
          }
      }

Thanks for your help 🤗

wow, thanks for this, your code indeed fixed my issue. thanks for sharing the correct code

miconda commented 2 years ago

Thanks! I pushed the suggested changes - commit referenced above.