Commit: 14f8c07aec4285ee376f5f88a64d3449e1e6b6ef Author: Peter Kokot <peterko...@gmail.com> Fri, 14 Dec 2018 15:22:18 +0100 Parents: 3a9021ab3a0ca634023a73f3c4220b67ba386be0 Branches: master
Link: http://git.php.net/?p=web/bugs.git;a=commitdiff;h=14f8c07aec4285ee376f5f88a64d3449e1e6b6ef Log: Refactor PDO wrapper Some considerations were raised on the mailing list that this PHP application doesn't need a PDO wrapper at all. Changes: - ::fetchRow() method removed in favor of the vanilla PDOStatement::fetch() - ::fetchAll() override removed in favor of the vanilla PDOStatement::fetchAll() - ::fetchCol() removed since it is not used and is only a wrapper for the PDOStatement::fetchColumn() - PDO fetch_style synced accross the app. When no fetch style is passed the default PDO::FETCH_ASSOC is used as set when connecting to db. - Remove Database::escape() method The custom ::escape() method is a wrapper around PDO::quote() which additionally trims leading and trailing quotes from the string. All this should ideally be done via prepared statements only, except where we can and need to use PDO::quote() this step can be done on the given string or variable at hand directly. - Remove escapeSQL() function The escapeSQL function is a wrapper around the PDO::quote() and is using $dbh from the global scope which is not testable nor good practice further on. Removed and refactored into only PDO::quote() usages on required places. - Remove ::fetchOne() method The fetchOne() method is a simple wrapper around the PDOStatement::fetch() method with very minor tweaks so the usage can be simplified even more. The PDOStatement::fetch(\PDO::FETCH_NUM)[0] will always return either a result from the database column or when row is empty a null. - Probably this should be refactored to the database tables respected repositories further on. - Remove PDO wrapper The app's current goal is to lean on a vanilla PDO wrapper only. Current set of features also don't require additional functionality and extending PDO to a wrapper or create a database abstraction layer yet. Changed paths: M include/functions.php M include/prepend.php M include/query.php M scripts/cron/email-assigned M scripts/cron/no-feedback D src/Database/Database.php M src/Database/Statement.php M src/Repository/ObsoletePatchRepository.php M src/Repository/PackageRepository.php M src/Repository/PatchRepository.php M src/Repository/PullRequestRepository.php M src/Utils/GitHub.php M src/Utils/PatchTracker.php M www/admin/index.php M www/api.php M www/bug-pwd-finder.php M www/index.php M www/lstats.php M www/report.php M www/stats.php M www/vote.php
diff --git a/include/functions.php b/include/functions.php index a45cda0..6206db3 100644 --- a/include/functions.php +++ b/include/functions.php @@ -279,30 +279,6 @@ function spam_protect($txt, $format = 'html') } /** - * Escape strings so they can be used as literals in queries - * - * @param string|array $in data to be sanitized. If it's an array, each element is sanitized. - * - * @return string|array the sanitized data - * - * @see oneof(), field(), txfield() - */ -function escapeSQL($in) -{ - global $dbh; - - if (is_array($in)) { - $out = []; - foreach ($in as $key => $value) { - $out[$key] = $dbh->escape($value); - } - return $out; - } else { - return $dbh->escape($in); - } -} - -/** * Goes through each variable submitted and returns the value * from the first variable which has a non-empty value * @@ -312,7 +288,7 @@ function escapeSQL($in) * * @return mixed the value, if any * - * @see escapeSQL(), field(), txfield() + * @see field(), txfield() */ function oneof() { @@ -334,7 +310,7 @@ function oneof() * * @return mixed the data requested * - * @see escapeSQL(), oneof(), txfield() + * @see oneof(), txfield() */ function field($n) { @@ -1075,13 +1051,13 @@ function get_old_comments($bug_id, $all = 0) // skip the most recent unless the caller wanted all comments if (!$all) { - $row = $res->fetchRow(PDO::FETCH_NUM); + $row = $res->fetch(\PDO::FETCH_NUM); if (!$row) { return ''; } } - while (($row = $res->fetchRow(PDO::FETCH_NUM)) && strlen($output) < $max_message_length && $count++ < $max_comments) { + while (($row = $res->fetch(\PDO::FETCH_NUM)) && strlen($output) < $max_message_length && $count++ < $max_comments) { $email = spam_protect($row[1], 'text'); $output .= "[{$row[0]}] {$email}\n\n{$row[2]}\n\n{$divider}\n"; } @@ -1091,7 +1067,7 @@ function get_old_comments($bug_id, $all = 0) if (!$res) { return $output; } - $row = $res->fetchRow(PDO::FETCH_NUM); + $row = $res->fetch(\PDO::FETCH_NUM); if (!$row) { return $output; } @@ -1256,7 +1232,7 @@ function get_package_mail($package_name, $bug_id = false, $bug_type = 'Bug') WHERE name = ? ')->execute([$package_name]); - list($list_email, $project) = $res->fetchRow(); + list($list_email, $project) = $res->fetch(\PDO::FETCH_NUM); if ($project == 'pecl') { $mailfrom = 'pecl-...@lists.php.net'; @@ -1270,7 +1246,7 @@ function get_package_mail($package_name, $bug_id = false, $bug_type = 'Bug') } else { // Get the maintainers handle if ($project == 'pecl') { - $handles = $dbh->prepare("SELECT GROUP_CONCAT(handle) FROM bugdb_packages_maintainers WHERE package_name = ?")->execute([$package_name])->fetchOne(); + $handles = $dbh->prepare("SELECT GROUP_CONCAT(handle) FROM bugdb_packages_maintainers WHERE package_name = ?")->execute([$package_name])->fetch(\PDO::FETCH_NUM)[0]; if ($handles) { foreach (explode(',', $handles) as $handle) { @@ -1290,7 +1266,7 @@ function get_package_mail($package_name, $bug_id = false, $bug_type = 'Bug') if ($bug_id) { $bug_id = (int) $bug_id; - $assigned = $dbh->prepare("SELECT assign FROM bugdb WHERE id= ? ")->execute([$bug_id])->fetchOne(); + $assigned = $dbh->prepare("SELECT assign FROM bugdb WHERE id= ? ")->execute([$bug_id])->fetch(\PDO::FETCH_NUM)[0]; if ($assigned) { $assigned .= '@php.net'; if ($assigned && !in_array($assigned, $to)) { @@ -1315,6 +1291,8 @@ function get_package_mail($package_name, $bug_id = false, $bug_type = 'Bug') */ function format_search_string($search, $boolean_search = false) { + global $dbh; + // Function will be updated to make results more relevant. // Quick hack for indicating ignored words. $min_word_len=3; @@ -1337,15 +1315,15 @@ function format_search_string($search, $boolean_search = false) foreach ($used as $word) { $newsearch .= "+$word "; } - return [" AND MATCH (bugdb.email,sdesc,ldesc) AGAINST ('" . escapeSQL($newsearch) . "' IN BOOLEAN MODE)", $ignored]; + return [" AND MATCH (bugdb.email,sdesc,ldesc) AGAINST (" . $dbh->quote($newsearch) . " IN BOOLEAN MODE)", $ignored]; // allow custom boolean search (raw) } elseif ($boolean_search === 2) { - return [" AND MATCH (bugdb.email,sdesc,ldesc) AGAINST ('" . escapeSQL($search) . "' IN BOOLEAN MODE)", $ignored]; + return [" AND MATCH (bugdb.email,sdesc,ldesc) AGAINST (" . $dbh->quote($search) . " IN BOOLEAN MODE)", $ignored]; } } // require any of the words (any) - return [" AND MATCH (bugdb.email,sdesc,ldesc) AGAINST ('" . escapeSQL($search) . "')", $ignored]; + return [" AND MATCH (bugdb.email,sdesc,ldesc) AGAINST (" . $dbh->quote($search) . ")", $ignored]; } /** @@ -1415,7 +1393,6 @@ function unsubscribe($bug_id, $hash) { global $dbh; - $hash = escapeSQL($hash); $bug_id = (int) $bug_id; $query = " @@ -1424,7 +1401,7 @@ function unsubscribe($bug_id, $hash) WHERE bug_id = ? AND unsubscribe_hash = ? LIMIT 1 "; - $sub = $dbh->prepare($query)->execute([$bug_id, $hash])->fetch(PDO::FETCH_ASSOC); + $sub = $dbh->prepare($query)->execute([$bug_id, $hash])->fetch(); if (!$sub) { return false; @@ -1458,8 +1435,8 @@ function get_resolve_reasons($project = false) $where = ''; if ($project !== false) { - $project = escapeSQL($project); - $where.= "WHERE (project = '{$project}' OR project = '')"; + $project = $dbh->quote($project); + $where.= "WHERE (project = {$project} OR project = '')"; } $resolves = $variations = []; @@ -1467,7 +1444,7 @@ function get_resolve_reasons($project = false) if (!$res) { throw new Exception("SQL Error in get_resolve_reasons"); } - while ($row = $res->fetchRow(PDO::FETCH_ASSOC)) { + while ($row = $res->fetch()) { if (!empty($row['package_name'])) { $variations[$row['name']][$row['package_name']] = $row['message']; } else { @@ -1502,7 +1479,7 @@ function bugs_get_bug($bug_id) WHERE b.id = ? GROUP BY bug'; - return $dbh->prepare($query)->execute([$bug_id])->fetchRow(PDO::FETCH_ASSOC); + return $dbh->prepare($query)->execute([$bug_id])->fetch(); } /** @@ -1522,7 +1499,7 @@ function bugs_get_bug_comments($bug_id) WHERE c.bug = ? GROUP BY c.id ORDER BY c.ts "; - return $dbh->prepare($query)->execute([$bug_id])->fetchAll(PDO::FETCH_ASSOC); + return $dbh->prepare($query)->execute([$bug_id])->fetchAll(); } /** @@ -1562,7 +1539,7 @@ function verify_bug_passwd($bug_id, $passwd) { global $dbh; - return (bool) $dbh->prepare('SELECT 1 FROM bugdb WHERE id = ? AND passwd = ?')->execute([$bug_id, $passwd])->fetchOne(); + return (bool) $dbh->prepare('SELECT 1 FROM bugdb WHERE id = ? AND passwd = ?')->execute([$bug_id, $passwd])->fetch(\PDO::FETCH_NUM)[0]; } /** diff --git a/include/prepend.php b/include/prepend.php index 9e03d69..388ebb1 100644 --- a/include/prepend.php +++ b/include/prepend.php @@ -1,7 +1,7 @@ <?php use App\Autoloader; -use App\Database\Database; +use App\Database\Statement; // Dual PSR-4 compatible class autoloader. When Composer is not available, an // application specific replacement class is used. Once Composer can be added @@ -61,19 +61,24 @@ $docBugEmail = $site_data['doc_email']; $secBugEmail = $site_data['security_email']; $basedir = $site_data['basedir']; define('BUG_PATCHTRACKER_TMPDIR', $site_data['patch_tmp']); -define('DATABASE_DSN', "mysql:host={$site_data['db_host']};dbname={$site_data['db']};charset=utf8"); /** * Obtain the functions and variables used throughout the bug system */ require_once "{$ROOT_DIR}/include/functions.php"; -// Database connection (required always?) -$dbh = new Database(DATABASE_DSN, $site_data['db_user'], $site_data['db_pass'], [ - \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, - \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, - \PDO::ATTR_EMULATE_PREPARES => false, -]); +// Database connection with vanilla PDO to understand app architecture in no time +$dbh = new \PDO( + 'mysql:host='.$site_data['db_host'].';dbname='.$site_data['db'].';charset=utf8', + $site_data['db_user'], + $site_data['db_pass'], + [ + \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, + \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, + \PDO::ATTR_EMULATE_PREPARES => false, + \PDO::ATTR_STATEMENT_CLASS => [Statement::class], + ] +); // Last Updated.. $tmp = filectime($_SERVER['SCRIPT_FILENAME']); diff --git a/include/query.php b/include/query.php index da996d8..51ed807 100644 --- a/include/query.php +++ b/include/query.php @@ -88,7 +88,8 @@ if (isset($_GET['cmd']) && $_GET['cmd'] == 'display') if (!empty($package_name)) { $where_clause .= ' AND bugdb.package_name'; if (count($package_name) > 1) { - $where_clause .= " IN ('" . join("', '", escapeSQL($package_name)) . "')"; + $package_name = array_map([$dbh, 'quote'], $package_name); + $where_clause .= " IN (" . join(", ", $package_name) . ")"; } else { $where_clause .= ' = ' . $dbh->quote($package_name[0]); } @@ -97,7 +98,8 @@ if (isset($_GET['cmd']) && $_GET['cmd'] == 'display') if (!empty($package_nname)) { $where_clause .= ' AND bugdb.package_name'; if (count($package_nname) > 1) { - $where_clause .= " NOT IN ('" . join("', '", escapeSQL($package_nname)) . "')"; + $package_nname = array_map([$dbh, 'quote'], $package_nname); + $where_clause .= " NOT IN (" . join(", ", $package_nname) . ")"; } else { $where_clause .= ' <> ' . $dbh->quote($package_nname[0]); } @@ -169,19 +171,19 @@ if (isset($_GET['cmd']) && $_GET['cmd'] == 'display') } if ($php_os != '') { - $where_clause .= " AND bugdb.php_os {$php_os_not} LIKE '%" . $dbh->escape($php_os) . "%'"; + $where_clause .= " AND bugdb.php_os {$php_os_not} LIKE " . $dbh->quote('%'.$php_os.'%'); } if ($phpver != '') { - $where_clause .= " AND bugdb.php_version LIKE '" . $dbh->escape($phpver) . "%'"; + $where_clause .= " AND bugdb.php_version LIKE " . $dbh->quote($phpver.'%'); } if ($project != '') { - $where_clause .= " AND EXISTS (SELECT 1 FROM bugdb_pseudo_packages b WHERE b.name = bugdb.package_name AND b.project = '". $dbh->escape($project) ."' LIMIT 1)"; + $where_clause .= " AND EXISTS (SELECT 1 FROM bugdb_pseudo_packages b WHERE b.name = bugdb.package_name AND b.project = ". $dbh->quote($project) ." LIMIT 1)"; } if ($cve_id != '') { - $where_clause .= " AND bugdb.cve_id {$cve_id_not} LIKE '" . $dbh->escape($cve_id) . "%'"; + $where_clause .= " AND bugdb.cve_id {$cve_id_not} LIKE " . $dbh->quote($cve_id.'%'); } /* A search for patch&pull should be (patch or pull) */ @@ -213,12 +215,14 @@ if (isset($_GET['cmd']) && $_GET['cmd'] == 'display') if ($pseudo = array_intersect(array_keys($pseudo_pkgs), $package_name)) { $where_clause .= " OR bugdb.package_name"; if (count($pseudo) > 1) { - $where_clause .= " IN ('" . join("', '", escapeSQL($pseudo)) . "')"; + $pseudo = array_map([$dbh, 'quote'], $pseudo); + $where_clause .= " IN (" . join(", ", $pseudo) . ")"; } else { - $where_clause .= " = '" . implode('', escapeSQL($pseudo)) . "'"; + $where_clause .= " = " . $dbh->quote(reset($pseudo)); } } else { - $where_clause .= " OR bugdb.package_name IN ('" . join("', '", escapeSQL(array_keys($pseudo_pkgs))) . "')"; + $items = array_map([$dbh, 'quote'], array_keys($pseudo_pkgs)); + $where_clause .= " OR bugdb.package_name IN (" . join(", ", $items) . ")"; } $query .= "$where_clause )"; @@ -269,7 +273,7 @@ if (isset($_GET['cmd']) && $_GET['cmd'] == 'display') try { $result = $dbh->prepare($query)->execute()->fetchAll(); $rows = count($result); - $total_rows = $dbh->prepare('SELECT FOUND_ROWS()')->execute()->fetchOne(); + $total_rows = $dbh->prepare('SELECT FOUND_ROWS()')->execute()->fetch(\PDO::FETCH_NUM)[0]; } catch (Exception $e) { $errors[] = 'Invalid query: ' . $e->getMessage(); } diff --git a/scripts/cron/email-assigned b/scripts/cron/email-assigned index 6257c52..c1977d4 100755 --- a/scripts/cron/email-assigned +++ b/scripts/cron/email-assigned @@ -17,7 +17,7 @@ $sql = "SELECT id, package_name, bug_type, sdesc, status, assign, UNIX_TIMESTAMP $res = $dbh->query($sql); // Gather up the data -while ($row = $res->fetchRow(PDO::FETCH_ASSOC)) { +while ($row = $res->fetch()) { $data[$row['assign']][] = $row; } diff --git a/scripts/cron/no-feedback b/scripts/cron/no-feedback index a32b955..e3154f8 100755 --- a/scripts/cron/no-feedback +++ b/scripts/cron/no-feedback @@ -24,7 +24,7 @@ if ($dbh) WHERE status = 'Feedback' AND ts2 < DATE_SUB(NOW(), INTERVAL {$after}) ")->execute([]); - while ($bug = $res->fetchRow(PDO::FETCH_ASSOC)) + while ($bug = $res->fetch()) { list($mailto, $mailfrom, $bcc, $params) = get_package_mail($bug['package_name'], false, $bug['bug_type']); diff --git a/src/Database/Database.php b/src/Database/Database.php deleted file mode 100644 index 467f189..0000000 --- a/src/Database/Database.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -namespace App\Database; - -use App\Database\Statement; - -/** - * Thin PDO wrapper for bugs.php.net. - * - * @author Maciej Sobaczewski <so...@php.net> - */ -class Database extends \PDO -{ - /** - * When creating new PDO object, automagically switch PDOStatement with own - * extended implementation. - */ - public function __construct(string $dsn, string $username = '', string $password = '', array $options = []) - { - parent::__construct($dsn, $username, $password, $options); - - $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [Statement::class]); - } - - /** - * PDO puts apostrophes around the text so we need to strip the outermost - * characters. - */ - public function escape($text, $escape_wildcards = false) - { - return substr($this->quote($text), 1, -1); - } -} diff --git a/src/Database/Statement.php b/src/Database/Statement.php index 75b545b..f967ef9 100644 --- a/src/Database/Statement.php +++ b/src/Database/Statement.php @@ -13,34 +13,10 @@ class Statement extends \PDOStatement * \PDOStatement::execute(), on the other hand, returns boolean. Change it * to return $this and thus allow further method chaining. */ - public function execute($input_parameters = null) + public function execute($parameters = null): self { - parent::execute($input_parameters); + parent::execute($parameters); return $this; } - - public function fetchAll($fetchode = null, $rekey = false, $force_array = false, $group = false) - { - return parent::fetchAll(); - } - - public function fetchCol($colnum) - { - return parent::fetchColumn($colnum); - } - - public function fetchOne($colnum = 0, $rownum = null) - { - return $this->fetch(\PDO::FETCH_NUM)[0]; - } - - public function fetchRow($mode = null) - { - if (!$mode) { - $mode = \PDO::FETCH_BOTH; - } - - return $this->fetch($mode); - } } diff --git a/src/Repository/ObsoletePatchRepository.php b/src/Repository/ObsoletePatchRepository.php index 2335ec9..2682cee 100644 --- a/src/Repository/ObsoletePatchRepository.php +++ b/src/Repository/ObsoletePatchRepository.php @@ -2,8 +2,6 @@ namespace App\Repository; -use App\Database\Database; - /** * Repository for retrieving data from the bugdb_obsoletes_patches database table. */ @@ -11,14 +9,14 @@ class ObsoletePatchRepository { /** * Database handler. - * @var Database + * @var \PDO */ private $dbh; /** * Class constructor. */ - public function __construct(Database $dbh) + public function __construct(\PDO $dbh) { $this->dbh = $dbh; } diff --git a/src/Repository/PackageRepository.php b/src/Repository/PackageRepository.php index 178a485..96392c8 100644 --- a/src/Repository/PackageRepository.php +++ b/src/Repository/PackageRepository.php @@ -2,8 +2,6 @@ namespace App\Repository; -use App\Database\Database; - /** * Repository class for retrieving data from the bugdb_pseudo_packages database * table. @@ -12,7 +10,7 @@ class PackageRepository { /** * Database handler. - * @var Database + * @var \PDO */ private $dbh; @@ -27,7 +25,7 @@ class PackageRepository /** * Class constructor. */ - public function __construct(Database $dbh) + public function __construct(\PDO $dbh) { $this->dbh = $dbh; } diff --git a/src/Repository/PatchRepository.php b/src/Repository/PatchRepository.php index a3a6d87..971c1ff 100644 --- a/src/Repository/PatchRepository.php +++ b/src/Repository/PatchRepository.php @@ -2,8 +2,6 @@ namespace App\Repository; -use App\Database\Database; - /** * Repository for retrieving data from the bugdb_patchtracker database table. */ @@ -11,7 +9,7 @@ class PatchRepository { /** * Database handler. - * @var Database + * @var \PDO */ private $dbh; @@ -24,7 +22,7 @@ class PatchRepository /** * Class constructor. */ - public function __construct(Database $dbh) + public function __construct(\PDO $dbh) { $this->dbh = $dbh; $this->uploadsDir = BUG_PATCHTRACKER_TMPDIR; @@ -56,7 +54,7 @@ class PatchRepository $arguments = [$bugId, $patch, $revision]; - return $this->dbh->prepare($sql)->execute($arguments)->fetchOne(); + return $this->dbh->prepare($sql)->execute($arguments)->fetch(\PDO::FETCH_NUM)[0]; } /** @@ -83,7 +81,7 @@ class PatchRepository WHERE bugdb_id = ? AND patch = ? AND revision = ? '; - if ($this->dbh->prepare($sql)->execute([$bugId, $name, $revision])->fetchOne()) { + if ($this->dbh->prepare($sql)->execute([$bugId, $name, $revision])->fetch(\PDO::FETCH_NUM)[0]) { $contents = @file_get_contents($this->getPatchPath($bugId, $name, $revision)); if (!$contents) { diff --git a/src/Repository/PullRequestRepository.php b/src/Repository/PullRequestRepository.php index 64ab66a..89a72ce 100644 --- a/src/Repository/PullRequestRepository.php +++ b/src/Repository/PullRequestRepository.php @@ -9,13 +9,14 @@ class PullRequestRepository { /** * Database handler. + * @var \PDO */ private $dbh; /** * Class constructor. */ - public function __construct($dbh) + public function __construct(\PDO $dbh) { $this->dbh = $dbh; } diff --git a/src/Utils/GitHub.php b/src/Utils/GitHub.php index c551959..b31421e 100644 --- a/src/Utils/GitHub.php +++ b/src/Utils/GitHub.php @@ -9,6 +9,7 @@ class GitHub { /** * Database handler. + * @var \PDO */ private $dbh; @@ -30,7 +31,7 @@ class GitHub /** * Class constructor */ - public function __construct($dbh) + public function __construct(\PDO $dbh) { $this->dbh = $dbh; } diff --git a/src/Utils/PatchTracker.php b/src/Utils/PatchTracker.php index 127831a..028f9f1 100644 --- a/src/Utils/PatchTracker.php +++ b/src/Utils/PatchTracker.php @@ -3,7 +3,6 @@ namespace App\Utils; use App\Utils\Uploader; -use App\Database\Database; /** * Service for handling uploaded patches. @@ -12,7 +11,7 @@ class PatchTracker { /** * Database handler. - * @var Database + * @var \PDO */ private $dbh; @@ -49,7 +48,7 @@ class PatchTracker /** * Class constructor. */ - public function __construct(Database $dbh, Uploader $uploader) + public function __construct(\PDO $dbh, Uploader $uploader) { $this->dbh = $dbh; $this->uploadsDir = BUG_PATCHTRACKER_TMPDIR; diff --git a/www/admin/index.php b/www/admin/index.php index f7952a5..ebb905b 100644 --- a/www/admin/index.php +++ b/www/admin/index.php @@ -59,7 +59,7 @@ if ($action === 'phpinfo') { "); echo "<dl>\n"; - while ($row = $res->fetchRow(PDO::FETCH_ASSOC)) { + while ($row = $res->fetch()) { echo "<dt>", $row['name'], ": </dt>\n<dd>", mailto_list(explode(',', $row['list_email'])), "</dd>\n"; } echo "</dl>\n"; @@ -73,7 +73,7 @@ if ($action === 'phpinfo') { echo "<h3>List Responses</h3>\n"; $rows = []; - while ($row = $res->fetchRow(PDO::FETCH_ASSOC)) { + while ($row = $res->fetch()) { // This is ugly but works (tm) $row['message'] = nl2br($row['message']); @@ -86,13 +86,13 @@ if ($action === 'phpinfo') { $sql = "SELECT version() mysql_version\n"; - while ($row = $res->fetchRow(PDO::FETCH_NUM)) { + while ($row = $res->fetch(\PDO::FETCH_NUM)) { $table = $row[0]; $sql .= "\t, (SELECT COUNT(*) FROM `$table`) `cnt_$table`\n"; } $res = $dbh->query($sql); - $row = $res->fetchRow(PDO::FETCH_ASSOC); + $row = $res->fetch(); echo "<p>Running MySQL <b>".$row['mysql_version']."</b></p>"; unset($row['mysql_version']); @@ -110,7 +110,7 @@ if ($action === 'phpinfo') { $rows = []; $res = $dbh->query("SHOW TABLE STATUS"); echo "<h3>Table status:</h3>\n"; - while ($row = $res->fetchRow(PDO::FETCH_ASSOC)) { + while ($row = $res->fetch()) { $rows[] = $row; } diff --git a/www/api.php b/www/api.php index 4c664ee..4a07baf 100644 --- a/www/api.php +++ b/www/api.php @@ -27,7 +27,7 @@ if ($type === 'docs' && $action === 'closed' && $interval) { "; //@todo add error handling - $rows = $dbh->prepare($query)->execute([])->fetchAll(PDO::FETCH_ASSOC); + $rows = $dbh->prepare($query)->execute([])->fetchAll(); if (!$rows) { echo 'The fail train has arrived.'; exit; diff --git a/www/bug-pwd-finder.php b/www/bug-pwd-finder.php index ffe8a38..b124b22 100644 --- a/www/bug-pwd-finder.php +++ b/www/bug-pwd-finder.php @@ -29,7 +29,7 @@ if (isset($_POST['captcha']) && $bug_id != '') { $query = "SELECT email, passwd FROM bugdb WHERE id = '{$bug_id}'"; // Run the query - $row = $dbh->prepare($query)->execute()->fetchRow(PDO::FETCH_ASSOC); + $row = $dbh->prepare($query)->execute()->fetch(); if (is_null($row)) { $errors[] = "Invalid bug id provided: #{$bug_id}"; diff --git a/www/index.php b/www/index.php index b744d08..40e56ac 100644 --- a/www/index.php +++ b/www/index.php @@ -17,7 +17,7 @@ if($_SERVER['REQUEST_URI'] == '/random') { $query = "SELECT id FROM bugdb WHERE status NOT IN('Closed', 'Not a bug', 'Duplicate', 'Spam', 'Wont fix', 'No Feedback') AND private = 'N' ORDER BY RAND() LIMIT 1"; $result = $dbh->prepare($query)->execute(); - $id = $result->fetchRow(); + $id = $result->fetch(\PDO::FETCH_NUM); redirect("bug.php?id={$id[0]}"); } diff --git a/www/lstats.php b/www/lstats.php index ff8cc20..2a22c4c 100644 --- a/www/lstats.php +++ b/www/lstats.php @@ -23,14 +23,14 @@ function get_status_count ($status, $category = '') $excluded = "'Feature/Change Request', 'Systems problem', 'Website Problem', 'PEAR related', 'PECL related', 'Documentation problem', 'Translation problem', 'PHP-GTK related', 'Online Doc Editor problem'"; if ($category != '') { - $query.= " {$status} AND bug_type = 'Bug' AND package_name = '" . $dbh->escape($category). "' "; + $query.= " {$status} AND bug_type = 'Bug' AND package_name = " . $dbh->quote($category); } else { $query.= " status='{$status}' "; } $query.= "AND bug_type NOT IN({$excluded})"; $res = $dbh->prepare($query)->execute([]); - $row = $res->fetchRow(PDO::FETCH_NUM); + $row = $res->fetch(\PDO::FETCH_NUM); return $row[0]; } diff --git a/www/report.php b/www/report.php index 017cea1..7009edb 100644 --- a/www/report.php +++ b/www/report.php @@ -122,7 +122,7 @@ if (isset($_POST['in'])) { WHERE bug = ? ORDER BY id DESC LIMIT 1 - ")->execute([$row['id']])->fetchOne(); + ")->execute([$row['id']])->fetch(\PDO::FETCH_NUM)[0]; $summary = $row['ldesc']; if (strlen($summary) > 256) { diff --git a/www/stats.php b/www/stats.php index 8b161c4..1afc810 100644 --- a/www/stats.php +++ b/www/stats.php @@ -58,7 +58,7 @@ $query = " $result = $dbh->prepare($query)->execute(); -while ($row = $result->fetchRow(PDO::FETCH_ASSOC)) { +while ($row = $result->fetch()) { $pkg_tmp[$row['status']][$row['package_name']] = $row['quant']; @$pkg_total[$row['package_name']] += $row['quant']; @$all[$row['status']] += $row['quant']; @@ -160,7 +160,7 @@ $query = " SELECT DATE_FORMAT(ts1, '%Y-%m') as d, $result = $dbh->prepare($query)->execute(); $last_date = null; -while ($row = $result->fetchRow(PDO::FETCH_ASSOC)) { +while ($row = $result->fetch()) { if ($row['d'] != $last_date) { if ($last_date !== null) { echo "</table>\n\n"; diff --git a/www/vote.php b/www/vote.php index 94df5fe..e3e0a87 100644 --- a/www/vote.php +++ b/www/vote.php @@ -20,7 +20,7 @@ $reproduced = (int) $_POST['reproduced']; $samever = isset($_POST['samever']) ? (int) $_POST['samever'] : 0; $sameos = isset($_POST['sameos']) ? (int) $_POST['sameos'] : 0; -if (!$dbh->prepare("SELECT id FROM bugdb WHERE id= ? LIMIT 1")->execute([$id])->fetchOne()) { +if (!$dbh->prepare("SELECT id FROM bugdb WHERE id= ? LIMIT 1")->execute([$id])->fetch(\PDO::FETCH_NUM)[0]) { session_start(); // Authenticate @@ -63,7 +63,7 @@ $ip = ip2long(get_real_ip()); // Check whether the user has already voted on this bug. $bug_check = $dbh->prepare("SELECT bug, ip FROM bugdb_votes WHERE bug = ? AND ip = ? LIMIT 1") ->execute([$id, $ip]) - ->fetchRow(); + ->fetch(\PDO::FETCH_BOTH); if (empty($bug_check)) { // If the user vote isn't found, create one.
-- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php