<?php
require 'config.php';
require 'libraries/medoo/medoo.php';
$mdb = new medoo([
  'database_type' => 'mysql',
  'database_name' => $database['name'],
  'server' => $database['remote_host'],
  'username' => $database['user'],
  'password' => $database['password'],
  'charset' => 'utf8'
]);
$cols = $mdb->query("SHOW COLUMNS FROM clients")->fetchAll(PDO::FETCH_ASSOC);
echo "COLUMNS:" . PHP_EOL;
foreach ($cols as $c) { echo $c['Field'] . PHP_EOL; }
$rows = $mdb->query("SELECT id, name, COALESCE(active,0) AS active, CONCAT('[', COALESCE(google_ads_customer_id,''), ']') AS google_ads_customer_id FROM clients ORDER BY id ASC")->fetchAll(PDO::FETCH_ASSOC);
echo "ROWS=" . count($rows) . PHP_EOL;
foreach ($rows as $r) { echo json_encode($r, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) . PHP_EOL; }
$eligible = $mdb->query("SELECT id, name FROM clients WHERE COALESCE(active,0)=1 AND TRIM(COALESCE(google_ads_customer_id,''))<>'' ORDER BY id ASC")->fetchAll(PDO::FETCH_ASSOC);
echo "ELIGIBLE=" . json_encode($eligible, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) . PHP_EOL;
?>
