Jump to content

[SOLVED] Cannot connect to mysql server


GrayFox12

Recommended Posts

Hi guys,

 

Im just trying to connect to my mysql running on the same machine but am having difficulties.

 

Heres what I got:

 

mysql_connect("localhost:3306", "username", "password") or die("Unable to connect to server ".mysql_error());

 

        $h = "localhost:3306";

 

        $u = "username";

 

        $p = "password";

 

        $connection=mysql_connect($h,$u,$p);

 

        mysql_select_db("database") or die(mysql_error());

 

echo "here";

 

My problem is that this isnt working and I am left with a blank page with no error message so I dont even know what the problem is.  Please help me

 

cheers

 

GrayFox

Link to comment
Share on other sites

What do you get if you have just this on your page?

 

<?php
$h = "localhost";
$u = "username";
$p = "password";

$connection = mysql_connect($h,$u,$p) or die(mysql_error());
mysql_select_db("database", $connection) or die(mysql_error());

echo "here";				
?>

Link to comment
Share on other sites

How about if you have this...

 

<?php
$h = "localhost";
$u = "username";
$p = "password";

$connection = mysql_connect($h,$u,$p) or die("Connection");
mysql_select_db("database", $connection) or die("Database");

echo "here";            
?>

Link to comment
Share on other sites

You are likely getting a fatal runtime error because the mysql extension is not enabled.

 

Before you go any further trying to use php on your development system, please permanently set error_reporting to E_ALL and display_errors to ON in your php.ini so that php will help you by displaying all the errors it detects. Stop and start your web server to get any change made to php.ini to take effect and use a phpinfo() statement to confirm that the settings were actually changed in case the php.ini that you are changing is not the one that php is using.

 

You will save a ton of time leaning php, developing php code, and debugging php code by having those two settings as indicated.

Link to comment
Share on other sites

Ok I go into my php.ini file and it already says display_errors = on and error_reporting  =  E_ALL & ~E_NOTICE.

 

I stop and Restart xampp.  When I look at phpinfo it has display_errors = off.  I begginning to think its looking for the wrong php.ini file.  The file i looked at is in c:/Xampp/php is that correct?

Link to comment
Share on other sites

E_ALL & ~E_NOTICE

The above setting disables NOTICE messages. You should not disable NOTICE messages when you are developing and debugging php code as there will be a number of typeo's you will make and other novice errors that the NOTICE message will help you find and fix.

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.