Reputation: 87
I’m pretty new to CodeIgniter and php. I have this issue which I can’t figure out.
I am trying to start working on a CodeIgniter php site and I keep getting: Class 'DB' not found
I have an error on line 92 this is the line
try {
DB::connect(DB_ADAPTER, array(
'host' => DB_HOST,
'user' => DB_USER,
'pass' => DB_PASS,
'name' => DB_NAME,
'persist' => DB_PERSIST
)); // connect
if (defined('DB_CHARSET') && trim(DB_CHARSET)) {
DB::execute("SET NAMES ?", DB_CHARSET);
} // if
DB::execute('ROLLBACK');
DB::execute('UNLOCK TABLES');
DB::execute('SET AUTOCOMMIT=1');
} catch(Exception $e) {
if (Env::isDebugging()) {
Env::dumpError($e);
} else {
Logger::log($e, Logger::FATAL);
Env::executeAction('error', 'db_connect');
} // if
} // try
Upvotes: 1
Views: 232
Reputation: 15609
Don't use this method. Go to your applications -> config -> database.php
and enter in your database credentials there.
Then head to applications -> config -> autoload.php
and in the libraries
array add database
eg:
$autoload['libraries'] = array('database');
(Should be around line 55).
Then, you can use the database guide and Codeigniter's built in database helper to do what you want.
You want to do all of these in your model
. E.g:
function madeup_stuff($id){
$query = $this->db->get_where("table_name", array("id" => $id));
$data = array();
foreach ($query as $q){
$data[] = $q;
}
}
Upvotes: 1