NO JOY unable to use cdr reports php script

balefireeyed

Member
Joined
Sep 5, 2013
Messages
53
Reaction score
3
Successfully used the following php script a freepbx distro installation. I'm wondering what is preventing it from working on piaf purple.

PHP:
#!/usr/bin/env php
<?php
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
  include_once('/etc/asterisk/freepbx.conf');
}
$outfile = '/cdrreports/csvreport.csv';
$dbh = \FreePBX::Database();
$sql = "SELECT * FROM asteriskcdrdb.cdr WHERE date(calldate) >= date(now()-interval 1 day);";
$stmt = $dbh->prepare($sql);
$stmt->execute();
$ret = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$colnames = array_keys($ret[0]);
$csv = fopen($outfile,'w+');
fputcsv($csv,$colnames);
foreach($ret as $row){
  fputcsv($csv,$row);
}
fclose($csv);

The error that I'm getting when I run php file.php is this:

Code:
PHP Fatal error:  Class 'FreePBX' not found in /root/run_csv.php on line 7
 

balefireeyed

Member
Joined
Sep 5, 2013
Messages
53
Reaction score
3
I get the same thing on PIAF Green freepbx version 2.11.0.43

Code:
PHP Fatal error:  Class 'FreePBX' not found in /root/test.php on line 7
 

Members online

Forum statistics

Threads
25,824
Messages
167,828
Members
19,249
Latest member
jetest
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top