I tried to rename my database (I am using hostmonster) and now nothing is loading on my page. I can't seem to find any documentation anywhere on this. I renamed the database back to what it originally was and I still getting the same error and nothing is loading on my page now. I am using codeigniter (as the title would suggest). The following error is:
A Database Error Occurred
Unable to select the specified database: xxxxx
Filename: core/Loader.php
Line Number: 346
I go to this file and there is nothing of relevance there:
// Load the DB class
$CI->db =& DB($params, $active_record);
Do I have to completely re-install my files to the server now? Here is what database.php looks like...
$active_group = 'main';
$active_record = TRUE;
$db['main']['hostname'] = 'localhost';
$db['main']['username'] = 'xxxx';
$db['main']['password'] = 'xxxx';
$db['main']['database'] = 'xxxx';
$db['main']['dbdriver'] = 'mysql';
$db['main']['dbprefix'] = '';
$db['main']['pconnect'] = TRUE;
$db['main']['db_debug'] = TRUE;
$db['main']['cache_on'] = FALSE;
$db['main']['cachedir'] = '';
$db['main']['char_set'] = 'utf8';
$db['main']['dbcollat'] = 'utf8_general_ci';
$db['main']['swap_pre'] = '';
$db['main']['autoinit'] = TRUE;
$db['main']['stricton'] = FALSE;
Obviously, I don't really use the (xxxx)'s...
In your control panel , go to MySQL Databases
I assumed you have already created a user , Now what you are missing out ... is that you did not add the user to the database
after adding , confirm the necessary permission , then you are good to go!
Set $db['default']['pconnect'] = FALSE;. Here mysql_pconnect() is disabled, So we are using mysql_connect().
open application->config->database.php
and set the configuration variable
$db['default']['database'] = 'new name';
Using command prompt/terminal, type in the following from your mysql bin folder:
mysql -u USER -h localhost -p PASSWORD DATABASENAME
See if that throws any issues at you (wrong password, wrong database name, etc..). Make sure you use the same text from your configs (copy/paste).
I had same problem under CPanel.
It helped to set:
$db['main']['db_debug'] = FALSE;
Related
$db_host = "";
$db_user = "";
$db_pass = "";
$db_name = "";
I have to fill out these, so I wanted to check but I used 'ampps' to install mysql.
so I couldn't find info in my database.
where should I check in below pic?
mysql wrokbench
wrokbench2
Detault mysql login credentials in AMPPS are :
Username : root
Pass : mysql
You can create a new database using phpMyAdmin :
http://localhost/phpmyadmin/
This question already has answers here:
Codeigniter - multiple database connections
(8 answers)
Closed 4 years ago.
Afternoon all.
I have a strange question.
I need to have two connections to our db in codeigniter instance.
I need to have the standard ci method but i also need to create a pdo class instance for use in new feature setup.
We are unfortunately in the position where we have to run a v1.0 system using the old db connectivity and a new v2.0 system using a pdo db object.
How can I go about creating a global instance of this pdo class so that it only gets instantiated once per process call to codeigniter.
you should add another DB in application/config/database.php and change dbdriver and hostname like
$db['pdodb']['hostname'] = "mysql:host=localhost'";
$db['pdodb']['username'] = "root";
$db['pdodb']['password'] = "";
$db['pdodb']['database'] = "your_db";
$db['pdodb']['dbdriver'] = "pdo";
$db['pdodb']['dbprefix'] = "";
$db['pdodb']['pconnect'] = TRUE;
$db['pdodb']['db_debug'] = FALSE;
$db['pdodb']['cache_on'] = FALSE;
$db['pdodb']['cachedir'] = "";
$db['pdodb']['char_set'] = "utf8";
$db['pdodb']['dbcollat'] = "utf8_general_ci";
$db['pdodb']['swap_pre'] = "";
$db['pdodb']['autoinit'] = TRUE;
$db['pdodb']['stricton'] = FALSE;
and you can load database like this
$pdodb= $this->load->database('pdodb', TRUE);
and finally you can execute query like this
$query = $pdodb->select('col1, col2,col3')->get('your_table');
for more information about multiple database
I have codeigniter configured to use multiple databases. For some customers, we need to query an additional database so this is a matter of:
if( isConfigured(database) )
foo();
However, the attempts I have made have either given the same result whether or not the db is configured in databases.php, or throws an error.
I have attempted the following:
if( $this->load->database('optional') == FALSE )
Which raises the error You have specified an invalid database connection group
try( $this->load->database('optional') )
{
foo();
}
catch(Exception $e)
{
doNothing();
}
Which raises the same error
The documentation states that $this->load->database('optional', TRUE) returns the connection ID however I cannot check this as the code errors out before returning a value.
I was expecting to be able to check whether or not a property had been set, e.g. $this->config->item('db')['optional'] but this would be largely guesswork to determine how to access the correct property
I have also looked into the dbutil class but this only applies to databases which have already established a connection.
$db['db1']['hostname'] = 'localhost';
$db['db1']['username'] = 'root';
$db['db1']['password'] = '';
$db['db1']['database'] = 'mydatabase';
$db['db1']['dbdriver'] = 'mysql';
$db['db1']['dbprefix'] = '';
$this->load->database('db1',TRUE);
$option = array();
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = 'localhost'; // Database host name
$option['user'] = '*****'; // User for database authentication
$option['password'] = '********'; // Password for database authentication
$option['database'] = 'teste_dados'; // Database name
$db = JDatabase::getInstance( $option );
// Create a new query object.
$query = $db->getQuery(true);
/*
// Insert columns.
$columns = array('id_teste','testes','time');
// Insert values.
$values = array(4,'loucura3',date("h:i:s"));
// Prepare the insert query.
$query->insert($db->quoteName('teste1'));
$query->columns($db->quoteName($columns));
$query->values(implode(',', $values));
or
$query="INSERT INTO teste1('id_teste','testes','time') VALUES (4,'loucura3','".date("h:i:s")."')";
// Set the query using our newly populated query object and execute it.
$db->setQuery($query);
$db->execute();
Both options gives the following error message:
An error has occurred while processing your request.
You may not be able to visit this page because of:
an out-of-date bookmark/favourite
a mistyped address
a search engine that has an out-of-date listing for this site
you have no access to this page
Go to the Home Page
Home Page
If difficulties persist, please contact the System Administrator of this site and report the error below.
0 SQL=INSERT INTO teste1('id_teste','testes','time') VALUES (4,'loucura3','05:11:00')
I`ve seen some similar problems and their fixes and none of them workd for me any ideas?.
Try testing the sql script in mysql workbench or phpMyAdmin. Use backticks instead of single quotes around columns
Can't seem to find any solution to this, no matter how hard I google. I have a deadline tomorrow and need this to be resolved asap, hope that someone here can give me a hint :)
Basically I'm connecting to a MSSQL-server from PHP. Like so:
$db_server = 'servername';
$db_user = 'user';
$db_pwd = 'pwd';
$db_db = 'dbname';
$link = mssql_connect($db_server, $db_user, $db_pwd);
if (!$link || !mssql_select_db($db_db, $link)) {
die('Something went wrong while connecting to MSSQL');
}
After that I try to run this code:
mssql_query("CREATE TABLE ##TempUserTable (UserID VARCHAR(30))", $link);
And then I get this error:
Warning: mssql_query() [function.mssql-query]: Query failed in /var/www/test.php on line 4
And yes, I've fixed the serverstuff in freetds.conf and it should be able to create a temporary table. It worked before and it's working from Eclipse / SQLExplorer.
I'm getting frustrated!
Thanks in advance! :)