Database connecting
Posted: Thu Jan 21, 2010 11:33 am
Hey guys, I realize that there is another post about 3 down from mine (viewtopic.php?f=1&t=111800) that addresses a similar issue, but not quite the same problem.
I'm using CodeIgnighter as a framework to try to connect a mySQL database (created through phpmyadmin, if that makes a difference?) So I have the database set up as follows;
And I'm connecting using the database code within code ignighter too, which is;
I've barely touched upon PHP before, so I'm not sure if I'm doing anything wrong here, the layout of folders to files is correct so it's not the structure of the base files or anything. I'm also pretty sure that these set of codes won't print the database on screen either?
I'm trying to create a frontend that'll allow the user to input data then search for data at another time (it's a database for offenders at a resort). Any help is appreciated!
TIA RT.
I'm using CodeIgnighter as a framework to try to connect a mySQL database (created through phpmyadmin, if that makes a difference?) So I have the database set up as follows;
Code: Select all
<?php if ( ! defined('BASEPATH')) exit('...');
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "**";
$db['default']['password'] = "**";
$db['default']['database'] = "**";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "latin1_swedish_ci";
?>
And I'm connecting using the database code within code ignighter too, which is;
Code: Select all
<?php
function &DB($params = '', $active_record_override = FALSE)
{
if (is_string($params) AND strpos($params, '://') === FALSE)
{
include(APPPATH.'config/database'.EXT);
if ( ! isset($db) OR count($db) == 0)
{
show_error('No database connection settings were found in the database config file.');
}
if ($params != '')
{
$active_group = $params;
}
if ( ! isset($active_group) OR ! isset($db[$active_group]))
{
show_error('You have specified an invalid database connection group.');
}
$params = $db[$active_group];
}
elseif (is_string($params))
{
if (($dns = @parse_url($params)) === FALSE)
{
show_error('Invalid DB Connection String');
}
$params = array(
'dbdriver' => $dns['scheme'],
'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
);
if (isset($dns['query']))
{
parse_str($dns['query'], $extra);
foreach($extra as $key => $val)
{
if (strtoupper($val) == "TRUE")
{
$val = TRUE;
}
elseif (strtoupper($val) == "FALSE")
{
$val = FALSE;
}
$params[$key] = $val;
}
}
}
if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '')
{
show_error('You have not selected a database type to connect to.');
}
if ($active_record_override == TRUE)
{
$active_record = TRUE;
}
require_once(BASEPATH.'database/DB_driver'.EXT);
if ( ! isset($active_record) OR $active_record == TRUE)
{
require_once(BASEPATH.'database/DB_active_rec'.EXT);
if ( ! class_exists('CI_DB'))
{
eval('class CI_DB extends CI_DB_active_record { }');
}
}
else
{
if ( ! class_exists('CI_DB'))
{
eval('class CI_DB extends CI_DB_driver { }');
}
}
require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT);
$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
$DB =& instantiate_class(new $driver($params));
if ($DB->autoinit == TRUE)
{
$DB->initialize();
}
return $DB;
}
?>I'm trying to create a frontend that'll allow the user to input data then search for data at another time (it's a database for offenders at a resort). Any help is appreciated!
TIA RT.