#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171

    New PDO connects to non-existing host!


    It is ignoring the wrong hots name (HOST) and echos connected regardless of what I assign to HOST! I am on localhost!

    Please note when I change the username to a non-existing username, it fails to connect and gives me Access denied. So it is partially working!

    PHP Code:

    define
    (HOST'loch??$?$?$$$$$alhost');
    define(DATABASE'test');
    define(USER'test');
    define(PASS'');
    private function 
    __construct()
                {
                try {
                        
    $this->conn = new PDO('mysql:'.HOST.'=;dbname='.DATABASE.''USERPASS);
                        echo 
    "Connected";    
                }
                catch (
    PDOException $e)
                    {
                        print 
    "Error!: " $e->getMessage() . "<br/>";
                        die();
                    }
                } 
  2. #2
  3. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,959
    Rep Power
    4035
    It fails to connect just fine for me when I try something like that. You do have an extra = after your host parameter.

    Check your phpinfo() settings to see if something like sql.safe_mode is enabled.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171
    Originally Posted by kicken
    It fails to connect just fine for me when I try something like that. You do have an extra = after your host parameter.

    Check your phpinfo() settings to see if something like sql.safe_mode is enabled.
    Hey Kicken. I dont understand what you meant. I just used php.net's example:
    define("CONSTANT", "Hello world.");

    And sql.safe_mode is off.
  6. #4
  7. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,959
    Rep Power
    4035
    I see what you did upon closer inspection
    Code:
    $this->conn = new PDO('mysql:'.HOST.'=;dbname='.DATABASE.'', USER, PASS);
    The proper syntax for the mysql DSN is a string that looks like
    mysql:host=somehost.tld;dbname=somedb

    You messed up the host parameter by replacing the parameter name instead of trying to insert it's value.

    Since you did not specify any host in your DSN, mysql is just going to assume localhost.

    Code:
    $this->conn = new PDO('mysql:host='.HOST.';dbname='.DATABASE.'', USER, PASS);
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  8. #5
  9. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171
    Originally Posted by kicken
    I see what you did upon closer inspection
    Code:
    $this->conn = new PDO('mysql:'.HOST.'=;dbname='.DATABASE.'', USER, PASS);
    The proper syntax for the mysql DSN is a string that looks like
    mysql:host=somehost.tld;dbname=somedb

    You messed up the host parameter by replacing the parameter name instead of trying to insert it's value.

    Since you did not specify any host in your DSN, mysql is just going to assume localhost.

    Code:
    $this->conn = new PDO('mysql:host='.HOST.';dbname='.DATABASE.'', USER, PASS);
    AH! Good eyes! Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo