Jump to content

Connecting to Database using php objects


echosara

Recommended Posts

Hi I am trying to connect to my database but i am having some problems where the server( WAMP) crashes and does not load this page. here is the php coding

<?php

	$db = new PDO("mysql:host=localhost;dbname=test;port=80", "root", "");
	var_dump($db);

when i run this no error comes the page doesnt load. anyone know why? when using PDO do i have to do some sort of configuration changes to wamp? i have even changed the directory of the file and still same issue. any suggestions would be wonderful.

Why do you tell PDO that the database system is running on port 80? That's the port for HTTP, i. e. your webserver. The default port for MySQL is 3306. Unless you've changed this setting, just leave out the port parameter.

 

// Actually, this makes no sense at all. “localhost” means that you're connecting via a Unix domain socket. On the other hand, the port indicates that you're trying to connect via a network socket (IP + port). So which one is it?

i added error reporting to the script to make it like this

<?php

	$db = new PDO("mysql:host=localhost;dbname=test", "root", "");
	var_dump($db);
	error_reporting(E_ALL);

i would like to turn on display_errors on in php.ini; however i am having a hard time locating that in my wamp server. can you provide any directory to guide me.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.