payfrit-api/api/portal/myBusinesses.php
John Mizerek 1f81d98c52 Initial PHP API migration from CFML
Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3.
Shared helpers in api/helpers.php (DB, auth, request/response, security).
PDO prepared statements throughout. Same JSON response shapes as CFML.
2026-03-14 14:26:59 -07:00

35 lines
723 B
PHP

<?php
require_once __DIR__ . '/../helpers.php';
runAuth();
global $userId;
// Also check request body for UserID
$userID = $userId;
if ($userID <= 0) {
$data = readJsonBody();
$userID = (int) ($data['UserID'] ?? 0);
}
if ($userID <= 0) {
apiAbort(['OK' => false, 'ERROR' => 'not_logged_in', 'MESSAGE' => 'User not authenticated']);
}
$rows = queryTimed(
"SELECT b.ID, b.Name FROM Businesses b WHERE b.UserID = ? ORDER BY b.Name",
[$userID]
);
$businesses = [];
foreach ($rows as $row) {
$businesses[] = [
'BusinessID' => (int) $row['ID'],
'Name' => $row['Name'],
];
}
jsonResponse([
'OK' => true,
'BUSINESSES' => $businesses,
'COUNT' => count($businesses),
]);