/** * executes a SQL and returns a result dataset if appropriate. Use PDO object instead of execSQL() command as mysql_ functions are no longer maintained and have been deprecated. * @param string $sql Prepared SQL statement. Use ? character for placeholders * @param array $paramArray Array of parameters to apply into the prepared SQL statement. Values are replaced in sequence. * @param string $db Name of the database to execute the query against */ public static function execPDO($sql, $paramArray, $db) { // get more reference from http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers // intialize a PDO object $pdo = \GeniusFactor\Fibr\Sql\GFSql::getDSN(SQL_SERVER, SQL_USERNAME, SQL_PASSWORD, $db); // prep the SQL query to the PDO object $result = $pdo->prepare($sql); // if parameters are there, add them, otherwise call with no parameters. if (!is_null($paramArray) && count($paramArray) > 0) { $result->execute($paramArray); } else { $result->execute(); } return $result; }
/** * [getDSNFromGlobals description] * @method getDSNFromGlobals * @return [type] [description] */ function getDSNFromGlobals() { return \GeniusFactor\Fibr\Sql\GFSql::getDSN(CONFIG_SQL_SERVER, CONFIG_SQL_USERNAME, CONFIG_SQL_PASSWORD, CONFIG_SQL_DATABASE); }