gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

PDO Connection error #725

Closed realrecordzLab closed 5 years ago

realrecordzLab commented 5 years ago

I'm facing an error when I try to setup a connection with the database.

[21-Jun-2019 22:50:29 Europe/Berlin] PHP Fatal error:  Uncaught PDOException: Could not connect to database (mydatabase). in /Applications/MAMP/htdocs/xxx/vendor/gabordemooij/redbean/RedBeanPHP/Driver/RPDO.php:437
Stack trace:
#0 /Applications/MAMP/htdocs/xxx/vendor/gabordemooij/redbean/RedBeanPHP/Driver/RPDO.php(161): RedBeanPHP\Driver\RPDO->connect()
#1 /Applications/MAMP/htdocs/xxx/vendor/gabordemooij/redbean/RedBeanPHP/Driver/RPDO.php(461): RedBeanPHP\Driver\RPDO->runQuery('show tables', Array)
#2 /Applications/MAMP/htdocs/xxx/vendor/gabordemooij/redbean/RedBeanPHP/Driver/RPDO.php(482): RedBeanPHP\Driver\RPDO->GetAll('show tables', Array)
#3 /Applications/MAMP/htdocs/xxx/vendor/gabordemooij/redbean/RedBeanPHP/Adapter/DBAdapter.php(140): RedBeanPHP\Driver\RPDO->GetCol('show tables', Array)
#4 /Applications/MAMP/htdocs/xxx/vendor/gabordemooij/redbean/RedBeanPHP/QueryWriter/MySQL.php(180): RedBeanPHP\Adapter\DBAdapter->getCol('show tables')
#5 /Applications/MAMP/htdocs/xxx/vendor/gabordemooij/redbean/RedBeanPHP/ in /Applications/MAMP/htdocs/xxx/vendor/gabordemooij/redbean/RedBeanPHP/Driver/RPDO.php on line 437

here is the code that I use to setup the connection. It's correct, I followed the documentation. Is there a fix?

$dbh = R::setup('mysql:host=localhost;dbname=mydatabase','port=8889', 'root', 'root');
gabordemooij commented 5 years ago

Hi there,

2nd/3rd argument should be username, password. Maybe try:

$dbh = R::setup('mysql:host=localhost;dbname=mydatabase;port=8889', 'root', 'root');

realrecordzLab commented 5 years ago

@gabordemooij I've solved the issue. Thanks for the help.