Jump to content

Connecting to Database using php objects


echosara
Go to solution Solved by mac_gyver,

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.

Link to comment
Share on other sites

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?

Edited by Jacques1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.