简体   繁体   中英

Trying to get PDO Connection to Establish

I have been working on getting a PDO connection to establish within a class for the better half of a day. My problem is that as soon as I try to hit the new PDO(...) I get nothing, no errors nothing. Whatever I have after that will never run but my console will still be operational waiting for input. I have tried connecting in a few places including the "Driver" file where again, it doesn't do anything after I run the new PDO(...) instantiation. Here is part of my Database Class:

namespace App\Database;
class MySQL
{
    private $Host;
    private $DBName;
    private $DBTable;
    private $DBUser;
    private $DBPassword;
    private $DBPort;
    private $PDO;
    private $parameters;
    private $bConnected = false;
    public $querycount = 0;

    function __construct($DBName, $DBTable)
    {
        $this->Host = getenv("DATABASE_HOST");
        $this->DBPort =  getenv("DATABASE_PORT");
        $this->DBUser = getenv("DATABASE_USER");
        $this->DBPassword = getenv("DATABASE_PASSWORD");
        $this->DBName = $DBName;
        $this->DBTable = $DBTable;
        $this->Connect();
        $this->$parameters = array();
    }
    private function Connect()
    {
        try{
            echo "I am the good child and always print".PHP_EOL;
            $this->PDO = new PDO("mysql:host=localhost;port=33061;dbname=store", "root", "password");
            echo "Please Print Me <3".PHP_EOL;
            $this->bConnected = true;
        } catch (PDOException $e){
            echo $e->getMessage();
            die();
        }
    }

I have checked values for Host, DBPort etc and in this code below I have all their values hard coded so nothing should be wrong due to the formatting of insert the variables in their proper slots. I know PDO is turned on because I can use it in other projects but my catch isn't catching anything, I can get the first echo to run but the second one never appears. Any help would be awesome because at this point I am scratching my head at why I can't get this to connect.

Thanks!

If I am unclear I can try and provide clarity and I can also show the driver file if need be but basically, it is just calling the constructor just fine and the connect function is giving us problems.

I have been going over each line of my code for about the last hour or so if not more. I found some discrepancies in my variables. I used in a couple places $this->$parameters or other variations which didn't seem to cause an error for some reason but rendered the code inoperable. I'm not sure why it wasn't throwing an error about the variables but it would seem that is what caused my issue.

Thank you for your time and help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM