Jump to content

Can someone help me connect to mysql?


Recommended Posts

No matter what i do i cant connect to mysql. I spent a few hours the other day trying every possible connect statement. Here is what i have now. Some help would greatly be appreciated thanks Eric.

 

$con = mysql_connect("localhost","root","rhoads");

 

if (!$con)

  {

  die('Could not connect:' . mysql_error());

  }

else

{

echo "Good connection";

}

mysql_close($con);

Link to comment
https://forums.phpfreaks.com/topic/113617-can-someone-help-me-connect-to-mysql/
Share on other sites

What problems are you experiencing?

 

If you're getting a blank page then enable display_errors and make sure error_reporting is set to E_ALL. Save the php.ini and restart server and rerun your script, if you get an error such as "fatal error undefined mysql_connect" then you havn't enabled the mysql extension.

 

if you post your server setup (OS version, PHP version and Server version - example: XP SP2, PHP 5.2.6, Apache2.2.6) then we can help you.

What error do you get when you run that code? If you don't get an error, what do you see in front of you when you run that code? If you don't see anything when you run that code, what does a "view source" in your browser show?

 

Basically, we only see the information you provide in your post. If you don't tell us what you see in front of you, we cannot help.

How have you install Apache, PHP and MySQL? Using separate installers? If you have, go to php.net and download the zipped binaries package rather than the PHP installer. Extract the zip to where you have installed PHP to, now rename php.ini-recommended to just php.ini (remove the existing one)

 

Next step add PHP to the PATH Environment Variable.

 

Then open your php.ini and enable display_errors and make sure error_reporting is set to E_ALL. After find the following line:

extension_dir = .\

change it to

extension_dir = "C:/path/to/php/ext"

Change the text in blue

 

Scroll down and find the following line

;extension=php_mysql.dll

Remove the ; at the start of the line.

 

Save the php.ini and restart Apache. Rerun your test script.

Ok so you have followed everything I told you in my previous post. Then the next problem is PHP may not be reading the php.ini you're editing.

 

Adjust your script to this:

phpinfo();

$con = mysql_connect("localhost","root","rhoads");

if (!$con)
 {
 die('Could not connect:' . mysql_error());
 }
else
{
echo "Good connection";
}
mysql_close($con);

Run your script again, this time you'll get a web page rendered, with PHP's current settings.

The line you want to be concerned with is the Loaded Configuration File line. To the right of that line should be the full path to the php.ini PHP is reading for configuration,

it should read C:/path/to/php/php.ini

 

Can you confirm this?

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.