PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] Can we fire a database query in config/constants.php file to make constants dynamic? (Php Codeignitor)

 March 14, 2022     codeigniter, config, constants, dynamic, sql     No comments   

Issue

I have tried to place this at the bottom of the config/config.php

require_once( BASEPATH .'database/DB.php');
$db =& DB();

$query = $db->get('constants');
$result = $query->result();

foreach( $result as $row)
{
    $config[$row->title] = $row->value;
}

but it is throwing this error: An uncaught Exception was encountered

Type: Error Message: Class 'CI_Controller' not found Filename: E:\xampp74\htdocs\jrvs\system\core\CodeIgniter.php Line Number: 369

Please suggest me some solution for this. If this is not possible then what else we can do to make constants dynamic?


Solution

constants.php is the very first file that is loaded in Codeigniter.php so you can't use the instance of codeigniter in this file cause if hasn't been loaded yet and of course you can't rely on hooks because it loads after this file has been loaded and constants had been defined so!

You best option is to manually connect to your db in top of this file or in index.php and query what you need then use the values in define.



Answered By - Sherif Salah
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing