Posts

Showing posts with the label Global Variables

CodeIgniter - Best Place To Declare Global Variable

Answer : There is a file in /application/config called constants.php I normally put all mine in there with a comment to easily see where they are: /** * Custom defines */ define('blah', 'hello mum!'); $myglobalvar = 'hey there'; After your index.php is loaded, it loads the /core/CodeIgniter.php file, which then in turn loads the common functions file /core/Common.php and then /application/constants.php so in the chain of things it's the forth file to be loaded. I use a "Globals" class in a helper file with static methods to manage all the global variables for my app. Here is what I have: globals_helper.php (in the helpers directory) <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // Application specific global variables class Globals { private static $authenticatedMemberId = null; private static $initialized = false; private static function initialize() { ...

Cannot Set A Global Variable On Mysql

Answer : The variable name var does not reference a valid system variable. The GLOBAL and SESSION keywords in the SET statement are used for specifying the scope when setting MySQL system variables, not MySQL user variables. Try for example: SELECT @@global.net_read_timeout ; SET GLOBAL net_read_timeout = 45 ; SELECT @@global.net_read_timeout ; http://dev.mysql.com/doc/refman/8.0/en/set-statement.html http://dev.mysql.com/doc/refman/5.5/en/set-statement.html According to the MySQL 5.0 Reference Manual: User-defined variables are session-specific. That is, a user variable defined by one client cannot be seen or used by other clients. All variables for a given client session are automatically freed when that client exits. You could consider using an extension like MySQL Global User Variables UDF (old archived link) to use global (persistent shared) variables.