The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
New PDO connects to non-existing host!
Discuss New PDO connects to non-existing host! in the PHP Development forum on Dev Shed. New PDO connects to non-existing host! PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 11th, 2012, 10:15 PM
|
 |
A Change of Season
|
|
|
|
|
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.'', USER, PASS);
echo "Connected";
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
|

October 11th, 2012, 11:12 PM
|
 |
Wiser? Not exactly.
|
|
Join Date: May 2001
Location: Bonita Springs, FL
|
|
|
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.
|

October 12th, 2012, 01:14 AM
|
 |
A Change of Season
|
|
|
|
Quote: | 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.
|

October 12th, 2012, 05:31 AM
|
 |
Wiser? Not exactly.
|
|
Join Date: May 2001
Location: Bonita Springs, FL
|
|
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);
|

October 12th, 2012, 09:34 AM
|
 |
A Change of Season
|
|
|
|
Quote: | 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|