Jump to content

Connecting to Database using php objects


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.

  • Solution

you are likely getting a fatal runtime error. do you have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini on your development system so that php would report and display all the errors it detects?

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

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.

It doesn't help to turn on error reporting after the error has happened. You obviously need to do that before the error, either in the php.ini file or on top of the script.

 

The phpinfo() function tells you where your php.ini file is located.

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.