Jump to content

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
https://forums.phpfreaks.com/topic/176048-solved-cannot-connect-to-mysql-server/
Share on other sites

Thats the port where mysql instance is running on.  My xampp which is my webserver is on port 80.

 

Yea just completly blank word "here" does not show up.  When I remove the connection code "here" does come up so I know it is running php script.

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";				
?>

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";            
?>

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.

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?

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.

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.