PDO Construct error - PHP
I have created a wine shop in PHP that accesses a MySQL database and pulls the wines dat开发者_StackOverflowa onto a webpage. However, after getting it all working nicely I have now come across a PDO Construct error and do not know why.
The error is as follows:
Warning: PDO::__construct() [pdo.--construct]: [2002] A connection attempt failed because the connected party did not (trying to connect via HOSTNAME) in C:\webdev\shop\selectfromwines.php on line 5
It seems to relate to the following piece of code:
$database = new PDO('mysql:host=HOSTNAME; dbname=co525', 'co525', 'co525');
Any ideas where I might be going wrong?
P
is HOSTNAME real host name? If not - use correct address. If you have local db, try 127.0.0.1 or localhost
Open your php.ini and set the following:
pdo_mysql.default_socket=”/opt/lampp/var/mysql/mysql.sock”
精彩评论