Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

For Those Who Don't Have PDO

ShadowdareShadowdare r_j MVP
edited December 2010 in Vanilla 2.0 - 2.8
A question that usually would appear would be about an error relating to PDO shows up when you visit your freshly uploaded Vanilla 2.0.15 folder. It's obviously not a bug but I don't know where else to post this, but I originally had the question of "why am I getting an error about PDO?"

I wanted to help out by showing a small workaround. This happens because the PDO extension doesn't exist on the servers of your host. If your host, for some weird reason, denies enabling PDO, then there are workarounds available online. I managed to get PHPPDO to do it.

The error looks like this:
Class 'PDO' not found in /vanilla/conf/config-defaults.php

I downloaded PHPPDO and created a folder called "phppdo" in the root of my Vanilla folder. I then opened /vanilla/library/core/class.router.php and added these lines of code to the top:
function db_connect($dsn, $username = '', $password = '', $driver_options = array(), $path = './phppdo') { $driver = strtolower(trim(substr($dsn, 0, strpos($dsn, ':')))); if($driver && class_exists('PDO') && extension_loaded('pdo_' . $driver)) { $class = 'PDO'; } else { require_once($path . '/phppdo.php'); $class = 'PHPPDO'; } return new $class($dsn, $username, $password, $driver_options); } try { $db = db_connect('mysql:dbname=', 'dbuser', 'dbpass', array(), $_SERVER['DOCUMENT_ROOT'].'/vanilla/phppdo'); } catch(PDOException $e) { die($e->getMessage()); }

For the try statement, I added in my database info after each equals sign and the variables in $db. I'm not sure how to call the variables for $DatabaseName, $DatabaseUser, $DatabasePassword yet. If anyone knows how, please let me know.

After saving that file, I received another error like this one:
Cannot instantiate abstract class PDO in /vanilla/applications/dashboard/controllers/class.setupcontroller.php on line 120

So I opened that file up and went down to line 120 and changed it up:
Find:
$Connection = new PDO
Change that to:
$Connection = new PHPPDO

Then I received the same error for /vanilla/library/database/class.database.php. The same fix applies here on line 56:
Change:
$this->_Connection = new PDO
To:
$this->_Connection = new PHPPDO

Now you can run Vanilla without PDO installed on your server.

Add Pages to Vanilla with the Basic Pages app

Comments

  • MarkMark Vanilla Staff
    This is cool. I bet you could turn this into a plugin pretty easily. I bet @Todd has something to say about it...
  • @Mark, would plugin work during installation process?
  • ShadowdareShadowdare r_j MVP
    edited November 2010
    It would have to make use of $class as a global as well. The plugin would be an interesting idea but for new fresh installs the installation page won't be able to show up unless there's a if statement in the router to enable the plugin in case when no PDO is detected instead of doing these changes directly to the other two files. Actually, a plugin is more than is necessary. What do you think @Mark?

    Add Pages to Vanilla with the Basic Pages app

  • I do all this but show me:

    SQLSTATE[HY000] [1045] Access denied for user 'dbuser'@'localhost' (using password: YES)

    what now ? ;)
  • @lion91 i think you need to change the username and password to your host details
  • ShadowdareShadowdare r_j MVP
    edited December 2010
    @lion91: I think Kaos is right. Let us know what happens.
    $db = db_connect('mysql:dbname=', 'dbuser', 'dbpass', array(), $_SERVER['DOCUMENT_ROOT'].'/vanilla/phppdo');
    Add the dbname after the equals sign and change dbuser and dbpass. Also, make sure that the path to the phppdo is correct.

    Add Pages to Vanilla with the Basic Pages app

  • Thanks for the PDO tip Shadowdare!
    I have just used these mods to run Vanilla2 on my MoWeS local host.
    I was wondering if anyone has experienced any adverse affects from making these changes?
  • I've been running Vanilla without any problems for about a month now with PHPPDO.

    Add Pages to Vanilla with the Basic Pages app

  • What do you need to add to db_connect if your database isn't running on localhost?
  • Please try to use the following:
    $db = db_connect("mysql:host='your_hostname';dbname=", 'dbuser', 'dbpass', array(), $_SERVER['DOCUMENT_ROOT'].'/vanilla/phppdo');
  • I get this error when I make the first set of changes:

    Parse error: syntax error, unexpected T_TRY, expecting T_FUNCTION

    Any ideas?
  • dlefflerdleffler New
    edited January 2012

    For v2.0.18.1 some of the info has changed:

    in /vanilla/library/database/class.database.php

    • comment out line 55 ($this->IsPersistent ...
    • edit is now on line 58

    in /vanilla/library/core/class.router.php

    • you enter the code AFTER the opening line <?php
    • you must enter the database name, user name, and password

    in /vanilla/applications/dashboard/controllers/class.setupcontroller.php

    • edit is now on line 137

    Also, if you muck up the install along the way, you may have to empty the database (drop all the tables) and delete the /conf/config.php file.

  • For v2.0.18.2 some of the info has changed:

    in /vanilla/library/database/class.database.php

    • comment out line 54 ($this->IsPersistent ...
    • edit is now on line 57
    • also had to add require_once($_SERVER['DOCUMENT_ROOT'].'/external/vanilla/phppdo'. '/phppdo.php'); on line 29

    in /vanilla/library/core/class.router.php

    • you enter the code AFTER the opening line <?php
    • you must enter the database name, user name, and password

    in /vanilla/applications/dashboard/controllers/class.setupcontroller.php

    • edit is now on line 137

    Also, if you muck up the install along the way, you may have to empty the database (drop all the tables) and delete the /conf/config.php file.

    I seem to get timeout errors though when trying it with remote sites (rather than a local test site)

  • I now get this... Fatal error: Undefined class constant 'PDO::ATTR_DEFAULT_FETCH_MODE' in /home/emily/public_html/vanilla/phppdo/phppdo.php on line 361

    Any advice?

Sign In or Register to comment.