Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redbean php: Fatal error: Uncaught exception 'PDOException' with message 'Could not connect to database

Tags:

php

redbean

I have a very strange problem:

After deploying a small app to the prod server I am getting the following error:

Fatal error: Uncaught exception 'PDOException' with message 'Could not connect to     database.' in D:\inetpub\vhosts\DOMAIN\httpdocs\app\db\rb.php:194 
Stack trace: 
#0 D:\inetpub\vhosts\DOMAIN\httpdocs\app\db\rb.php(338): RedBean_Driver_PDO->connect() 
#1 D:\inetpub\vhosts\DOMAIN\httpdocs\app\db\rb.php(5674): RedBean_Driver_PDO->setDebugMode(true, Object(RedBean_Logger_Default)) 
#2 D:\inetpub\vhosts\DOMAIN\httpdocs\app\db\test.php(7): RedBean_Facade::debug(true) 
#3 {main} thrown inD:\inetpub\vhosts\DOMAIN\httpdocs\app\db\rb.php on line 194

I double checked host, user, db name and password and everything looks good.

I even created 2 php scripts:

//this one throws the error

require('rb.php');
R::setup('mysql:host=localhost;dbname=DBNAME', 'DBUSER','DBPASS'); //mysql
R::debug(true);
$testRecord = R::load('test', 1);
echo $testRecord->name;

//this one works fine

mysql_connect('localhost', 'DBUSER', 'DBPASS') or die(mysql_error());
mysql_select_db('DBNAME') or die(mysql_error());
$result = mysql_query("SELECT * FROM test")
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "Name: ".$row['name'];

what am I missing here? Please note that both scripts work fine on localhost. Also, localhost in a Linux machine while PROD is Windows. But why would that matter?

like image 226
nemnesic Avatar asked Dec 08 '25 22:12

nemnesic


2 Answers

So the problem was that the windows server does not have PDO mysql drivers installed.

like image 79
nemnesic Avatar answered Dec 10 '25 15:12

nemnesic


In linux ubuntu: sudo apt-get install php5-sqlite

Then restart your apache (sudo /etc/init.d/apache2 restart)

like image 41
jaycode Avatar answered Dec 10 '25 13:12

jaycode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!