Jump to content

HTTP 500 error when using MySQL


Hellok
 Share

Recommended Posts

I installed php, along with mysql and apache and got php and apache working properly together it seems. I have no problems when it comes to just using php code, to display a date for example, but when I try to use mysql, I get an HTTP 500 error. I've only gotten that error when there's a flaw with the code I've written. However, I copied and pasted the following example from the w3schools php mysql tutorial, to eliminate any of my stupid mistakes, yet I still get the error.<?php$con = mysql_connect("localhost","peter","abc123");if (!$con) { die('Could not connect: ' . mysql_error()); }if (mysql_query("CREATE DATABASE my_db",$con)) { echo "Database created"; }else { echo "Error creating database: " . mysql_error(); }mysql_close($con);?>I'm pretty new to web design.What could the problem be?I really appreciate any help, thanks.

Link to comment
Share on other sites

The problem could be anything. Turn on error reporting so you can figure out why.ini_set('display_errors', 1);error_reporting(E_ALL);If you're using IE, either use a different browser or disable friendly HTTP errors. You want the actual error message, not the default "there was an error" page.

Link to comment
Share on other sites

You should be able to search for "extensions" inside php.ini to find the list of extensions, and uncomment the line for mysql. I'm concerned if it's disabled though, you might not even have the mysql files. But, first try to enable the extension, restart the server, and try it again.

Link to comment
Share on other sites

Ok, there were two mysql lines. I'm not sure of the difference, but I uncommented both, restarted the server, then even my computer and had no success. extension=php_mysql.dllextension=php_mysqli.dllHowever, it did say this above the extensions, and I don't know if it could have anything to do with it.; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5); extension folders as well as the separate PECL DLL download (PHP 5).; Be sure to appropriately set the extension_dir directive.

Link to comment
Share on other sites

It sounds like you're not editing the correct php.ini file. Create a page with only this:

<?php phpinfo(); ?>

Near the top you'll see an entry called configuration file, and it will list which file it's actually using. You can also use that page to verify installed extensions, once you enable mysql you'll see a mysql section on that phpinfo page that shows the options that the mysql extension is using.

Link to comment
Share on other sites

Configuration File (php.ini) Path says C:\WindowsLoaded Configuration File says php.ini in the file folder I installed phpSo do I need to be editing the one in the Windows folder?If so, what about apache? Do I need to set any new paths? Everything associated with apache is in the loaded config file, and it is working fine.

Link to comment
Share on other sites

Well, it doesn't make sense that you would enable the extensions and restart the server, and they're still not enabled. That sounds like you're not editing the right file. If you're sure you're editing the right file then I'm not sure what to tell you. You might want to set up error logging, including reporting startup errors, and check the log after restarting the server to see if PHP is reporting any startup errors.

Link to comment
Share on other sites

I'm not really seasoned enough to be sure of anything. The php.ini file I've been editing was originally name php.ini-recommended. I followed this how to link http://www.ricocheting.com/how-to-install-on-windows/php. It told me to edit a file php.ini-dist. There wasn't one, so I tried the php.ini-recommended and everything went smoothly when configuring it with apache, so I assumed it was the right file.I'm confused what the C:\Windows path indicates. I can't find a php.ini file in the folder.

Link to comment
Share on other sites

The loaded configuration file should be the one it's using. It's looking in the Windows folder though, you might try to copy your php.ini to the Windows folder and see if that makes a difference.You might also just want to go through the php.ini and look at each of the options. There's a guide here with more information about some of the required ones:http://www.php.net/manual/en/install.windows.manual.phpThis page describes where PHP looks for the php.ini file:http://www.php.net/manual/en/configuration.file.phpThere are also some notes for Apache on Windows if you want to look at those:http://www.php.net/manual/en/install.windows.apache2.php

Link to comment
Share on other sites

Didn't work. I found this on another forum, but I don't know how to go about it or if it applies to me. "Make sure you have mysql installed and the php mysql module to go with it. If you installed from source, you will need to reconfigure and add the --with-mysql option. If you've installed through your OS package, make sure to get the package specifically setup for php and mysql."http://www.geeklog.net/forum/viewtopic.php?showtopic=54476I also saw someone on a different forum suggest the --with-mysql option. If this could be the problem, how do I fix it.

Edited by Hellok
Link to comment
Share on other sites

Those options are talking about rebuilding PHP from source. The Windows zip packages should all include the mysql extension. You actually don't need to install MySQL itself, as long as you have the mysql extension for PHP the functions in PHP will be defined regardless of whether or not MySQL (the program) is installed on the server.Just to verify, when you followed your installation instructions you downloaded the zip package, not the installer, correct? I don't think the installer includes many extensions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...