Skip to content

Commit e8141ba

Browse files
authored
Update MicrofyClass.php
1 parent b03ac34 commit e8141ba

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

MicrofyClass.php

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static function dbAll(PDO $pdo, string $sql, array $params = []): array
115115
{
116116
$stmt = $pdo->prepare($sql);
117117
$stmt->execute($params);
118-
return $stmt->fetchAll();
118+
return $stmt->fetchAll(PDO::FETCH_ASSOC);
119119
}
120120

121121
public static function dbOne(PDO $pdo, string $sql, array $params = []): mixed
@@ -326,44 +326,44 @@ public static function a(string $href, ?string $text = null, string $target = ''
326326
return "<a href=\"$href\"$targetAttr$classAttr>$text</a>";
327327
}
328328

329-
public static function htmlTable(array $array, string $class = '', string $id = ''): string
330-
{
331-
if (empty($array)) {
332-
return "<p><em>No data.</em></p>";
333-
}
334-
335-
$idAttr = $id !== '' ? " id='" . htmlspecialchars($id, ENT_QUOTES) . "'" : '';
336-
337-
if ($class !== '') {
338-
$tableTag = "<table{$idAttr} class='" . htmlspecialchars($class, ENT_QUOTES) . "'>";
339-
} else {
340-
$tableTag = "<table{$idAttr} border='1' cellpadding='6' cellspacing='0'>";
341-
}
342-
343-
$html = $tableTag;
344-
345-
// thead
346-
$html .= "<thead><tr>";
347-
foreach (array_keys($array[0]) as $col) {
348-
$html .= "<th>" . htmlspecialchars($col, ENT_QUOTES) . "</th>";
349-
}
350-
$html .= "</tr></thead>";
351-
352-
// tbody
353-
$html .= "<tbody>";
354-
foreach ($array as $row) {
355-
$html .= "<tr>";
356-
foreach ($row as $cell) {
357-
$html .= "<td>" . htmlspecialchars($cell, ENT_QUOTES) . "</td>";
358-
}
359-
$html .= "</tr>";
360-
}
361-
$html .= "</tbody>";
362-
363-
$html .= "</table>";
364-
365-
return $html;
366-
}
329+
public static function htmlTable(array $array, string $class = '', string $id = ''): string
330+
{
331+
if (empty($array)) {
332+
return "<p><em>No data.</em></p>";
333+
}
334+
335+
$idAttr = $id !== '' ? " id='" . htmlspecialchars($id, ENT_QUOTES) . "'" : '';
336+
337+
if ($class !== '') {
338+
$tableTag = "<table{$idAttr} class='" . htmlspecialchars($class, ENT_QUOTES) . "'>";
339+
} else {
340+
$tableTag = "<table{$idAttr} border='1' cellpadding='6' cellspacing='0'>";
341+
}
342+
343+
$html = $tableTag;
344+
345+
// thead
346+
$html .= "<thead><tr>";
347+
foreach (array_keys($array[0]) as $col) {
348+
$html .= "<th>" . htmlspecialchars($col, ENT_QUOTES) . "</th>";
349+
}
350+
$html .= "</tr></thead>";
351+
352+
// tbody
353+
$html .= "<tbody>";
354+
foreach ($array as $row) {
355+
$html .= "<tr>";
356+
foreach ($row as $cell) {
357+
$html .= "<td>" . htmlspecialchars($cell, ENT_QUOTES) . "</td>";
358+
}
359+
$html .= "</tr>";
360+
}
361+
$html .= "</tbody>";
362+
363+
$html .= "</table>";
364+
365+
return $html;
366+
}
367367

368368
// --- MISC OUTPUT ---
369369

@@ -425,18 +425,18 @@ public static function fail(string $msg = 'Error'): void
425425
self::json(['status' => 'fail', 'msg' => $msg]);
426426
}
427427

428-
public static function jsonArray(array $data): string
429-
{
430-
return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
431-
}
432-
433-
public static function jsonString(string $msg, bool $ok = true): string
434-
{
435-
return self::jsonArray([
436-
'status' => $ok ? 'ok' : 'fail',
437-
'msg' => $msg,
438-
]);
439-
}
428+
public static function jsonArray(array $data): string
429+
{
430+
return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
431+
}
432+
433+
public static function jsonString(string $msg, bool $ok = true): string
434+
{
435+
return self::jsonArray([
436+
'status' => $ok ? 'ok' : 'fail',
437+
'msg' => $msg,
438+
]);
439+
}
440440

441441

442442
// --- STRING ---
@@ -513,25 +513,25 @@ public static function span(string $text = '', string $class = ''): void
513513
echo "<span" . self::classAttr($class) . ">$text</span>";
514514
}
515515

516-
public static function div(string $text, array $attrs = []): string
517-
{
518-
$attrStr = self::buildAttr($attrs);
519-
return "<div$attrStr>$text</div>";
520-
}
516+
public static function div(string $text, array $attrs = []): string
517+
{
518+
$attrStr = self::buildAttr($attrs);
519+
return "<div$attrStr>$text</div>";
520+
}
521521
public static function section(string $text = '', string $class = ''): void
522522
{
523523
echo "<section" . self::classAttr($class) . ">$text</section>";
524524
}
525525

526-
public static function buildAttr(array $attrs): string
527-
{
528-
$parts = [];
529-
foreach ($attrs as $k => $v) {
530-
$parts[] = "$k=\"" . htmlspecialchars($v) . "\"";
531-
}
532-
533-
return $parts ? ' ' . implode(' ', $parts) : '';
534-
}
526+
public static function buildAttr(array $attrs): string
527+
{
528+
$parts = [];
529+
foreach ($attrs as $k => $v) {
530+
$parts[] = "$k=\"" . htmlspecialchars($v) . "\"";
531+
}
532+
533+
return $parts ? ' ' . implode(' ', $parts) : '';
534+
}
535535

536536
// --- CODE BLOCKS ---
537537

0 commit comments

Comments
 (0)