Skip to content

Instantly share code, notes, and snippets.

@jwieder
Created July 19, 2016 23:08
Show Gist options
  • Save jwieder/278e33ec6953f4434bf8c7fa432590cb to your computer and use it in GitHub Desktop.
Save jwieder/278e33ec6953f4434bf8c7fa432590cb to your computer and use it in GitHub Desktop.
A simple PHP script that allows users that allows WHMCS users to retrieve Product Bundle details including Display Price, Description, et al. Responses output is JSON encoded. Tested in WHMCS v6.3.
<?php
// HTTP USAGE:
// http://example.com/GetBundles.php?bid=
// BASH CLI EXAMPLE USAGE:
// export QUERY_STRING="bid=2" ; php -e -r 'parse_str($_SERVER["QUERY_STRING"], $_GET); include "GetBundles.php";'
$db_host = "mysql.databasehost.ext";
$db_name = "mysqlDatabaseName";
$db_user = "MysqlUsername";
$db_pass = "MySq1p@Ssw0rd!";
$BUNDLE = $_GET["bid"];
$link = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
$link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$link->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$link->quote($BUNDLE);
$stmt = $link->prepare("SELECT * FROM tblbundles WHERE id = :bid");
$stmt->bindParam(':bid', $BUNDLE, PDO::PARAM_STR);
$stmt->execute();
$dbRow = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($dbRow, JSON_UNESCAPED_UNICODE);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment