Welcome Guest, Not a member yet? Register   Sign In
Connecting to the database problem
#1

[eluser]Thomas Edwards[/eluser]
Having an issue with connecting to a database, usual message:

"Unable to connect to your database server using the provided settings."

If I use a standard script, like so, it connects fine and gets data.
Code:
<?php

DEFINE (DB_USER, "username");
DEFINE (DB_PASSWORD, "password");
DEFINE (DB_HOST, "localhost");
DEFINE (DB_NAME, "database");

$db_connection = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);

mysql_select_db (DB_NAME);

$query = "SELECT * FROM stories";
$result = mysql_db_query (DB_NAME, $query, $db_connection);
while ($row = mysql_fetch_array($result)) {
    echo 'entry';
}

?>

However, pop the same working settings into CI and it always returns that error. Any ideas?
#2

[eluser]mddd[/eluser]
Not all web / database servers support persistent connections. Try setting the config 'pconnect' setting to false.
#3

[eluser]Prophet[/eluser]
Triple check the settings in config/database.php and make sure $db['default']['dbdriver'] is set to "mysql".

Maybe you could post your config/database.php?
#4

[eluser]Thomas Edwards[/eluser]
Thanks for the advice Prophet, checked that.

mddd – totally worked. Does the persistent just create a slight slowdown whenever you access the database?
#5

[eluser]Prophet[/eluser]
Sorry for giving the obvious advice Tongue

Persistent connections are database connections that don't close once the script has finished being executed. They reduce latency by removing the need to create a new connection every time a database resources is requested but can increase load in the database server. (Was that what you were asking?)
#6

[eluser]mddd[/eluser]
@Thomas: Prophet's explanation is correct. However if your webserver and database server are on the same machine (as in most standard shared hosting packages) the extra time will be minimal.
#7

[eluser]Thomas Edwards[/eluser]
It’s on a client’s shared hosting package but should have fairly minimal traffic. Thanks for the advice guys!




Theme © iAndrew 2016 - Forum software by © MyBB