Please note that the forum isn't realy used anymore.

If you have questions, want support or just simply want to talk to us you can find us on slack.

 

SpoonDatabase connection Exception

Hello, i think i read many threads similar this topic but i can really figure out why spoondatabase returning me always the same error :
throw new SpoonDatabaseException('A database connection could not be established.', 0, $this->password);

So, this is what i have: -hosting provider (siteground.com) ensured me that hostname is localhost and the port i 3306 -i checked mysql db credentials and i'm sure that are correct in parameters.yml. -i deleted all cache file (listed in many topics in this forum and in the remove-cache sh script). I also manually deleted /prod and /dev folder(like suggested in my previous topic) inside app/cache and every time reset to 777 permission recursively. Yes at the first page request the /prod folder comes renewed BUT not the dev folder -I watched inside the renewed app/cache/prod/appProdDebugProjectContainer.php at line 285 and the db credentials are up-to-date and correct

-Notice: My db password contains diacritics

I have attempted to: -substitute hostname with 127.0.0.1, -change password with somethingelse without diacritics -upload and substitutes the functioning /app/cache folders from local to online hosting -force the credentials hardcoding the strings in spoondatabase.php(but i advice not to do that) -run the old php db_connect with credential and that connection worked

And everytime i've done cache cleaning,toggled debug modes in parameters.yml/putenv('FORK DEBUG'), checked every meaning file.

I did not run the console script because i don't have ssh but i read it is the same to remove the prod and dev folder...

The Exception comes out right after this: $this->services['database'] = $instance = new \SpoonDatabase('mysql', 'localhost', 'correct-username', 'correct-psw', 'correct-db-name', 3306);

and the right after:

exception at SpoonDatabase ->execute ('SET CHARACTER SET :charset, NAMES :charset, time_zone = "+0:00"', array('charset' => 'utf8')) with unsetted parameters:

$instance->execute('SET CHARACTER SET :charset, NAMES :charset, time_zone = "+0:00"', array('charset' => 'utf8'));

It seems that spoon cannot load the charset, so i wonder if the problem was the charset but i think not, by the way this is the charset query of mysql:

-Variable_name: Value:

-charactersetclient utf8mb4

-charactersetconnection utf8mb4

-charactersetdatabase utf8

-charactersetfilesystem binary

-charactersetresults utf8mb4

-charactersetserver utf8

-charactersetsystem utf8

-collationconnection utf8mb4general_ci

-collationdatabase utf8general_ci

-collationserver utf8general_ci

The only difference between my local site and the online one is the collation in my local mysql is utf8 not utf8mb4 and i cannot change it in hosted mysql. All tables and the db are utf8-general-ci like in my local db. In parameter.yml kernel.charset is 'utf-8'.

I know i'd been verbose, but i think to have done everything i could do, following all i could find in this forum similar to my problem. BUT if someone has some advice i will appreciate any kind of help

Are you sure it has something to do with the charset? The error doesn't help a lot, but maybe you can get the actual exception to show up:

in SpoonDatabase.php on line 157, the exception is caught and the "could not connect to db" message is printed. Maybe you can print out the $e exception instead? With var_dump() or something like that? or \Spoon::dump($e, true);

ok, the exception dumped is an huge array thousand of lines of code, but in the first lines i notice this:

object(PDOException)#46 (8) { ["message":protected] => string(97) "SQLSTATE[28000] [1045] Access denied for user 'correct-username'@'localhost' (using password: YES)" ["string":"Exception":private] => string(0) "" ["code":protected] => int(1045) ["file":protected] => string(75) "/home/studi798/publichtml/vendor/spoon/library/spoon/database/database.php" ["line":protected] => int(150) ["trace":"Exception":private] => array(15) { [0] => array(6) { ["file"] => string(75) "/home/studi798/publichtml/vendor/spoon/library/spoon/database/database.php" ["line"] => int(150) ["function"] => string(11) "__construct" ["class"] => string(3) "PDO" ["type"] => string(2) "->" ["args"] => array(3) { [0] => string(96) "mysql:host=localhost;dbname=correct-db-name;user=correct-username;password=correct-password;port=3306" [1] => string(15) "correct-username" [2] => string(12) "correct-password" } }

then the following part of the arry is the dumped exception sidechained in synfony, then facebook, then in the model ecc.., and so on like in the stack trace non-dumped. i hope these are meaningful lines. I'm wondering it is a permission issue maybe? according to my remote file system the vendor folder and respective subfolder has 755 permission, and the file database.php has 644. I didn't checked every single file in spoon library but i think they are all 644(the files not the folders) I didn't thik to change permission to the vendor libraries accordingly with this thread and this, maybe should I?

p.s. isn't strange that it does not regenerate the /app/cache/dev folder even if debug is set to true?

I don't think it has something to do with file permissions. SpoonDatabase just tries to connect to the database server from your hosting and the access gets denied by the server. Have you tried connecting to the database with something else than fork cms? (a simple php script that accesses database, or wordpress or another cms, etc). Then we can conclude that it's a database issue or it's a bug in fork cms or Spoon.

I guess that your username doesn't have privileges on the mysql server or something? But that would be strange, because the hosting usually takes care of this

sure, i temporaly used a new index.php in the site root with this <?php $db = mysql _ connect('localhost','*correct_user*','*correct_psw*'); if(!$db) {echo "Cannot connect to the database - incorrect details"; } else{echo "db_con OK";} $db_sel=mysql_select_db('*correct_db_name*'); if(!$db_sel) {echo "Cannot select the database - incorrect details"; } else{echo "db_sel OK";} mysql_close(); ?> And it echoed all ok, BUT in the information_schema db no user//db// password i created are shown there is only a default one that is not me. this is odd now i check the host providers asking them too to this problem, thanks for help in the meantime and sorry if i bother you!

Ok let me know if it works and if they could help you :-)!

OK, solved! In the end it wasn't a fork issue. mysql manager on the hosting provider did not update the db user password correctly, so i had to change the same password a couple of times,then it worked. i'm sorry for all this fuss and i really appreciated the support !

Glad it's solved. Have fun using Fork!

Comment

The forum is deprecated in favor of our Slack channel, which provides real-time support for your issues.

Join us on Slack here: https://fork-cms.herokuapp.com/