Created
March 19, 2016 08:47
-
-
Save anytizer/4f8cfde8b47d182b4970 to your computer and use it in GitHub Desktop.
Database of PHP Constants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/plain'); | |
/** | |
* Fix to: Maximum execution time of 30 seconds exceeded. | |
* Loop can fail in-between otherwise. | |
*/ | |
set_time_limit(0); | |
$mysqli = new MySQLi('localhost', 'USERNAME', 'PASSWORD', 'test'); | |
mysqli_report(MYSQLI_REPORT_ALL); | |
$mysqli->query("DROP TABLE IF EXISTS php_constants;"); | |
$mysqli->query("CREATE TABLE `php_constants` ( | |
`constant_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Constant ID', | |
`constant_category` varchar(255) NOT NULL DEFAULT '' COMMENT 'Constant Category', | |
`constant_name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Constant Name', | |
`constant_value` varchar(255) DEFAULT '' COMMENT 'Defined Constant Value', | |
PRIMARY KEY (`constant_id`) | |
);"); | |
$register = function ($category, $name, $value) use ($mysqli) { | |
$statement = $mysqli->prepare("INSERT INTO php_constants(constant_category, constant_name, constant_value) VALUES (?, ?, ?);"); | |
$statement->bind_param("sss", $category, $name, $value); | |
$statement->execute(); | |
}; | |
$constants = get_defined_constants(true); | |
foreach ($constants as $category => $eav) { | |
foreach ($eav as $name => $value) { | |
$register($category, $name, $value); | |
} | |
} | |
/** | |
* On-Screen Output confirms the constants were recorded in the database | |
*/ | |
print_r($constants); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment