Western Mass Hosting's Articles

Why Responsive Web Design Is So Important

Why Responsive Web Design Is So Important

Mobile internet browsing is on the rise people!  As of this posting the number of people browsing the internet from a mobile device is up to 18% vs. a declining 82% browsing from a desktop computer.  These numbers are up 6% since this time last year. ~ http://gs.statcounter.com/#mobile_vs_desktop-ww-monthly-201209-201309 What does this…

Cookie Notice

This site utilizes cookies to improve your browsing experience, analyze the type of traffic we receive, and serve up proper content for you. If you wish to continue browsing, you must agree to allow us to set these cookies. If not, please visit another website.

Simple PDO Wrapper Class and Functions

Hey folks, since PDO is taking over, I figured it was prime time for me to jump the bandwagon of direct db access, and take the plunge into PDO.As a result, I have built myself a nice and simple PDO Wrapper class and some extra functions to do all the work that one would need to do against a MySQL database.So we are going to split this up into the 2 files I have setup for my testing and environment, all are commented, and if you ‘do not get it’, well, maybe you should seek other hand holders to guide you through the basics of programming for the web ;-PWithout any further ado:

db.class.php

<?phpclass o7thDB {	/* ------------------------------------------------------------------ */
	// Public Properties
	/* ------------------------------------------------------------------ */
	public $Host 		 = '';		 // The host server we are connecting to
	public $Name 		 = '';		 // The name of the database
	public $User 		 = '';		 // The user to login with
	public $Pass 		 = '';		 // The password to login with
	public $Query 		 = '';		 // The query to execute
	public $Params 		 = array();	// An array of parameters to pass to the query for execution
	public $Exceptions 	 = '';		 // Returns a string representing the exception that occurred if any
	public $RecordCount 	= 0;		 // Returns a count of records returned, only used on SelectAll
	public $LastID		 = 0;		 // Returns the last ID of the reocrd inserted, per the Execute function
	/* ------------------------------------------------------------------ */
	// Internal Properties
	/* ------------------------------------------------------------------ */
	protected $DBHandle;
	/* ------------------------------------------------------------------ */
	// Connect to our db, and set the handle
	/* ------------------------------------------------------------------ */
	protected function Connect(){
		$dsn = array("mysql:host=$this->Host;dbname=$this->Name", $this->User, $this->Pass);
		try{
			// Set out internal db handle with the dsn values from above
			$this->DBHandle = new PDO($dsn[0], $dsn[1], $dsn[2]);
			// if the db type is mySQL, set some attributes
			$this->DBHandle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
			$this->DBHandle->setAttribute(PDO::ATTR_PERSISTENT, true);
			$this->DBHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			unset($dsn);
		} catch (PDOException $e) {
			// this should catch any error that may occur when trying to set our handle
			$this->Exceptions = $e->getMessage();
			exit;
		}
	}	// Destroying Everything
	public function __destruct(){
		$this->DBHandle = null;
		$this->Cache = null;
		$this->Host = null;
		$this->Name = null;
		$this->User = null;
		$this->Pass = null;
		$this->Query = null;
		$this->Params = array();
		$this->Exceptions = null;
		unset($this->DBHandle, $this->Cache, $this->Host, $this->Name, $this->User, $this->Pass, 
				$this->Query, $this->Params, $this->Exceptions);
	}	// Executes a query against the database, returns boolean success
	public function Execute(){
		$ret = false;
		// connect to the db, and get the handle
		$this->Connect();
		try{
			// prepare our query for execution
			$stmt = $this->DBHandle->prepare($this->Query);
			//Bind our parameters
			$this->BindParameters($stmt, $this->Params);
			// execute the query, passing in any parameters necessary for execution, then return if it was successful or not
			$ret = $stmt->execute($this->Params);
			$this->LastID = $this->DBHandle->lastInsertId(); 
		}catch (Exception $e) {
			// Try to catch any exception and throw it into our Exceptions property.
			$this->Exceptions = $e->getMessage();
			$ret = false;
		}
		return $ret;
	}	// Executes a select statement against the database, single record array
	public function SelectSingle(){
		// connect to the db, and get the handle
		$this->Connect();
		try{
			// prepare our query for execution
			$stmt = $this->DBHandle->prepare($this->Query);
			//Bind our parameters
			$this->BindParameters($stmt, $this->Params);
			// execute the query, passing in any parameters necessary for execution, then return if it was successful or not
			$stmt->execute($this->Params);
			// fetch the 1st row into a single record array
			$ret = $stmt->fetch();
			return $ret;
			// probably never gets fired, but we'll try anyways.... clean up
			$stmt->closeCursor();
			unset($stmt, $ret);
		}catch (Exception $e) {
			// Try to catch any exception and throw it into our Exceptions property.
			$this->Exceptions = $e->getMessage();
		}
	}	// Executes a select statement against the database, returns an associative array, also populates the record count property
	public function SelectAll(){
		// connect to the db, and get the handle
		$this->Connect();
		try{
			// prepare our query for execution
			$stmt = $this->DBHandle->prepare($this->Query);
			//Bind our parameters
			$this->BindParameters($stmt, $this->Params);
			// execute the query, passing in any parameters necessary for execution, then return if it was successful or not
			$stmt->execute($this->Params);
			// fetch the 1st row into an associative array of records
			$ret = $stmt->fetchAll(PDO::FETCH_ASSOC);
			// Populate our RecordCount return property
			$this->RecordCount = count($ret);
			return $ret;
			// probably never gets fired, but we'll try anyways.... clean up
			$stmt->closeCursor();
			unset($stmt, $ret);
		}catch (Exception $e) {
			// Try to catch any exception and throw it into our Exceptions property.
			$this->Exceptions = $e->getMessage();
		}
	}	// Prepare and bind our parameters
	protected function BindParameters($Stmnt, $Params){
		// loop over params, grab the length, datatype, and value
		$pCt = count($Params);
		for($i = 0; $i < $pCt; ++$i){
			switch(strtolower(gettype($Params[$i]))){
				case 'boolean':
					$Stmnt->bindParam('?', $Params[$i], PDO::PARAM_BOOL);	
					break;
				case 'integer':
				case 'double':
				case 'float':
					$Stmnt->bindParam('?', $Params[$i], PDO::PARAM_INT);	
					break;
				case 'null':
					$Stmnt->bindParam('?', $Params[$i], PDO::PARAM_NULL);	
					break;
				default:
					$Stmnt->bindParam('?', $Params[$i], PDO::PARAM_STR, strlen($Params[$i]));	
			}
		}
	}}
?>

db.functioning.php

<?php	/* ------------------------------------------------------------------ */
	// Change the path here to the class file
	require_once($_SERVER['DOCUMENT_ROOT'] . '/inc/classes/db.class.php');
	/* ------------------------------------------------------------------ */
	// Retrieve an associative array of records from the query run
	/* ------------------------------------------------------------------ */
	function SelectAll($args){
		// fire up the class
		$db = new o7thDB();
		// sett all our properties
		$db->Host = $args['DB']['DBHost'];
		$db->Name = $args['DB']['DBName'];
		$db->User = $args['DB']['DBUser'];
		$db->Pass = $args['DB']['DBPass'];
		// Set a query to run	
		$db->Query = $args['Query']['SQL'];
		// Set some parameters to be run against the query
		$db->Params = $args['Query']['Parameters'];
		// clean up the methods arguments as they are not necessary past this point
		$args = null;
		unset($args);
		// Retrieve all records into an associative array of records
		$ret = $db->SelectAll();	
		// If there is an exception, show it
		echo $db->Exceptions;
		// Clean up
		$db = null;
		unset($db);
		// Return the array
		return $ret;
	}
	/* ------------------------------------------------------------------ */
	// Retrieve an associative array of columns/1 record from the query run
	/* ------------------------------------------------------------------ */
	function SelectSingle($args){
		// fire up the class
		$db = new o7thDB();
		// sett all our properties
		$db->Host = $args['DB']['DBHost'];
		$db->Name = $args['DB']['DBName'];
		$db->User = $args['DB']['DBUser'];
		$db->Pass = $args['DB']['DBPass'];
		// Set a query to run	
		$db->Query = $args['Query']['SQL'];
		// Set some parameters to be run against the query
		$db->Params = $args['Query']['Parameters'];
		// clean up the methods arguments as they are not necessary past this point
		$args = null;
		unset($args);
		// Select a single record into a 1 record array
		$ret = $db->SelectSingle();
		// If there is an exception, show it
		echo $db->Exceptions;
		// Clean up
		$db = null;
		unset($db);
		// Return the array
		return $ret;
	}
	/* ------------------------------------------------------------------ */
	// Get a count of records from the query run
	/* ------------------------------------------------------------------ */
	function GetRecordCount($args){
		// fire up the class
		$db = new o7thDB();
		// sett all our properties
		$db->Host = $args['DB']['DBHost'];
		$db->Name = $args['DB']['DBName'];
		$db->User = $args['DB']['DBUser'];
		$db->Pass = $args['DB']['DBPass'];
		// Set a query to run	
		$db->Query = $args['Query']['SQL'];
		// Set some parameters to be run against the query
		$db->Params = $args['Query']['Parameters'];
		// clean up the methods arguments as they are not necessary past this point
		$args = null;
		unset($args);
		// Retrieve all records into an associative array of records, we really only need to fire this up to get the record count
		$db->SelectAll();	
		// If there is an exception, show it
		echo $db->Exceptions;
		// Get the count of records returned
		$rCt = $db->RecordCount;
		// Clean up
		$db = null;
		unset($db);
		$ret = null;
		unset($ret);
		// Return our record count
		return $rCt;
	}
	/* ------------------------------------------------------------------ */
	// Execute a query against the statement specified, and return a boolean value
	/* ------------------------------------------------------------------ */
	function Execute($args){
		global $lastId;
		// fire up the class
		$db = new o7thDB();
		// sett all our properties
		$db->Host = $args['DB']['DBHost'];
		$db->Name = $args['DB']['DBName'];
		$db->User = $args['DB']['DBUser'];
		$db->Pass = $args['DB']['DBPass'];
		// Set a query to run	
		$db->Query = $args['Query']['SQL'];
		// Set some parameters to be run against the query
		$db->Params = $args['Query']['Parameters'];
		// clean up the methods arguments as they are not necessary past this point
		$args = null;
		unset($args);
		// Execute the query, and return if it was successful or not
		$ret = $db->Execute();		
		if($db->LastID > 0){
			$lastId = $db->LastID;
		}
		// If there is an exception, show it
		echo $db->Exceptions;
		// Clean up
		$db = null;
		unset($db);
		// Return whether the execution was successful or not
		return $ret;
	}
	/* ------------------------------------------------------------------ */?>

Now, by all means, if you can make this better, leave me some comments with your suggestions, and as I figure out better ways to do this, I will post them here.Have fun coding!~Kevin

Our Privacy Policy

Last Updated: June 18th, 2025

Introduction

Western Mass Hosting (“we,” “our,” or “us”) respects the privacy of all individuals and organizations that interact with our services. This Privacy Policy establishes our practices regarding the collection, use, disclosure, and protection of personal information for visitors to our website and clients utilizing our managed hosting and WordPress services. By accessing our website or engaging our services, you acknowledge that you have read and understood this policy in its entirety.

Scope and Applicability

This Privacy Policy governs our handling of information collected through our corporate website and in the course of providing managed hosting, WordPress maintenance, and development services. In accordance with global privacy regulations, we serve as a Data Controller for information related to our business operations and client relationships. When processing data on behalf of our clients through hosted services, we act as a Data Processor under applicable data protection laws.

Information We Collect

We collect various categories of information necessary to provide and improve our services. This includes personal contact and payment details provided during account registration, technical information such as IP addresses and device characteristics for security purposes, and records of communications through support channels. For clients utilizing our hosting services, we may process end-user data stored within client websites, though we do not control or monitor the collection practices of such data.

Purpose and Legal Basis for Processing

We process personal information only when we have proper justification under applicable laws. The primary legal bases for our processing activities include the necessity to fulfill contractual obligations to our clients, our legitimate business interests in maintaining and improving our services, and in limited cases, explicit consent for specific marketing communications. We maintain detailed records of processing activities to demonstrate compliance with legal requirements.

Use of Collected Information

The information we collect serves multiple business purposes. Primarily, we use this data to deliver and maintain reliable hosting services, including server provisioning, performance monitoring, and technical support. We also utilize information for business operations such as billing, customer relationship management, and service improvement initiatives. Security represents another critical use case, where we analyze data to detect and prevent fraudulent activity or unauthorized access to our systems.

Data Sharing and Third-Party Disclosures

We engage with carefully selected third-party service providers to support our operations, including cloud infrastructure providers, payment processors, and customer support platforms. These relationships are governed by strict contractual agreements that mandate appropriate data protection measures. We may disclose information when legally required to comply with court orders, government requests, or to protect our legal rights and the security of our services.

International Data Transfers

As a global service provider, we may transfer and process data in various locations worldwide. When transferring personal data originating from the European Economic Area or other regulated jurisdictions, we implement appropriate safeguards such as Standard Contractual Clauses and rely on adequacy decisions where applicable. Our subprocessors, including AWS Lightsail, maintain robust compliance certifications to ensure the protection of transferred data.

Data Retention Practices

We retain personal information only for as long as necessary to fulfill the purposes outlined in this policy. Client account information is typically maintained for five years following service termination to comply with legal and financial reporting obligations. Backup data associated with hosting services is automatically purged after thirty days, as specified in our Terms of Service. For data processed on behalf of clients, retention periods are determined by the respective client’s policies and instructions.

Security Measures

We implement comprehensive technical and organizational security measures to protect personal information against unauthorized access, alteration, or destruction. Our security program includes network encryption protocols, regular vulnerability assessments, strict access controls, and employee training on data protection best practices. We maintain incident response procedures to address potential security breaches and will notify affected parties where required by law.

Individual Rights

Individuals whose personal data we process may exercise certain rights under applicable privacy laws. These rights may include requesting access to their information, seeking correction of inaccurate data, requesting deletion under specific circumstances, and objecting to particular processing activities. We have established procedures to handle such requests in accordance with legal requirements, typically responding within thirty days of receipt. Requests should be submitted to our designated Data Protection Officer through the contact information provided in this policy.

Cookies and Tracking Technologies

Our website employs various technologies to enhance user experience and analyze site performance. Essential cookies are used for basic functionality and security purposes, while analytics cookies help us understand how visitors interact with our site. Marketing cookies are only deployed with explicit user consent. Visitors can manage cookie preferences through their browser settings or our cookie consent tool.

Policy Updates and Notifications

We periodically review and update this Privacy Policy to reflect changes in our practices or legal obligations. Material changes will be communicated to affected clients through email notifications at least thirty days prior to implementation. Continued use of our services following such notifications constitutes acceptance of the revised policy.

Contact Information

For questions or concerns regarding this Privacy Policy or our privacy practices, please contact our Data Protection Officer at info@westernmasshosting.com or by mail at:

Western Mass Hosting
22 Orlando. St.,
Feeding Hills, MA 01030.

We take all privacy-related inquiries seriously and will respond promptly to legitimate requests. For clients with specific data processing agreements, please reference your contract for any additional terms that may apply to our handling of your data.