2

A little background for context: I'm pretty new to programming and such, and I have been trying for the past few months to set up a development environment on my laptop so I can practice with some basic stuff--PHP, Javascript, MySQL, possibly Python in the near future--and I have spent the past few months, off-and-on, trying to set up this environment with mixed results. I installed Apache 2.2, PHP 5.4.30, and MySQL 5.6 and have been tinkering with it the past couple nights trying to figure out on my own why a few things aren't working.

Right now my issue is this:

I'm trying to put together some basic pages on my localhost that will use HTML and PHP to connect to MySQL to enter things into a database with an HTML form page. The HTML works fine, obviously, but the PHP doesn't seem to want to play with MySQL. I keep getting error messages saying things like this:

Fatal error: Call to undefined function mysql_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\MtG_DB_files\browse.php on line 24.

The relevant lines on the script I'm writing are as follows:

$host="localhost";
$user="XXXXX";
$password="YYYYY";
$dbname="mtg";
/*$cxn=mysql_connect($host,$user,$password,$dbname)or die("Not connecting!");*/
$cxn=mysql_connect("localhost","XXXXX","YYYYY","mtg")or die("Failed to connect to MySQL");

mysql_select_db($cxn,"cardscatalog")or die("Failed to connect to Cards Catalog");

Half of me thinks my problem is syntax and the other thinks the problem is some kind of installation error. This all worked fine when I was initially learning it in grad school and using the school's servers and their installations of everything, so I have been able to do it in the past, I just have to figure out what I installed wrong on my personal laptop and how. I know this is a common problem and I've searched around the Internet trying to find a solution.

So far I've tried:

  1. Checking to make sure my dll files in php.ini are there and uncommented
  2. Making sure the php.ini file is reading from the right location
  3. Updating my versions of PHP, Apache, and MySQL (all are currently the versions I indicated previously) and double-checking that they're the right versions
  4. Making sure the right dll files are in the right locations (php_mysql.dll and php_mysqli.dll are in C:\php\ext)
  5. I've been obsessively restarting Apache and MySQL whenever I make changes
  6. I made sure Apache had read/write access to the access.log file, after reading about that on another site.
  7. Out of desperation, I remembered that in my grad school projects, once or twice something would work in IE but not Chrome or vice versa, so I've tried using both browsers to view the pages I'm creating. No dice.

What else can I do or try? I've got to be coming at this from the wrong angle. Is there some kind of updated or unincluded file(s) I should download? Please let me know of any specs I should include or any additional info needed to help figure this out; as you can see, I'm quite new to this and really don't know what I'm doing. On a related note, please be specific and fairly idiot-proof if you care to respond...I'm not joking when I say I'm a noob and I don't really speak the jargon and such.;-)Thank you for your time!

EDIT--7/15/14 00:13am Adding a link to my php.ini file for clarification.

php.ini

EDIT--7/15/14 23:37pm I'm wondering if this part of my phpinfo gives any useful information:

Path C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Sony\VAIO Startup Setting Tool;C:\Users\XXXXXX\AppData\Local\Smartbar\Application\;C:\Users\Marisa\AppData\Local\Smartbar\Application\;C:\Program Files\jEdit;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\MySQL\MySQL Utilities 1.4.3\;C:\Program Files (x86)\MySQL\MySQL Utilities 1.4.3\Doctrine extensions for PHP\

PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

EDIT--7/16/14 10:33 Well I tried re-installing PHP and MySQL last night and nothing doing--no perceptible change in the errors I've been getting. I think what might be affecting the problem is that a few of my extensions might have been from older versions of PHP and MySQL I tried to install, so I updated php_mysqli.dll, php_mysql.dll, and php_mbstring.dll, and put them in C:\php\ext and C:\Windows (covering my bases by using both locations), but I discovered I don't appear to have a libmysql.dll file anywhere in the places I thought it might be! I've done a little Googling around and it looks like people recommend against downloading a separate libmysql.dll file...what might be a good way to solve this?

  • Sounds like your verified that apache is working, but what about PHP. Try an echo and that will tell you if PHP is working or not. Do you have phpmyadmin or any other client installed that you can use to manage MySQL? – EternalHour Jul 15 '14 at 02:14
  • check to make sure that there isn't a ";" before "extension=php_mysql.dll" in php.ini located in the php folder. I was able to recreate the error by commenting it out. You have to restart the server when you change it. – craniumonempty Jul 15 '14 at 02:38
  • @craniumonempty, I made sure it's not commented out--no luck. – recoveringn00b Jul 15 '14 at 03:01
  • @EternalHour When I run phpinfo, I wrote the script for it with a quick line of echo to test for php...that shows up fine and my phpinfo does too, although it doesn't show MySQL or MySQLi. It DOES show MySQLnd...is that a useful clue at all? – recoveringn00b Jul 15 '14 at 03:02
  • Part of why I'm having the problem is that I'm trying to install phpmyadmin...trying to open it on my localhost gives me another, similar error message: `Fatal error: Call to undefined function mb_detect_encoding() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\phpMyAdmin-4.2.5-english\libraries\php-gettext\gettext.inc on line 177`. They both seem to have the common problem of failing to connect something or else thinking that what should be a defined function is not--I was working on that error message as a separate issue, but perhaps they're related? – recoveringn00b Jul 15 '14 at 03:02
  • 1
    mysqlnd is the native driver. you need another extension.. Is PDO installed? Maybe they knew that mysql extension was being deprecated and didn't install it.. Then again you don't have mbstring installed. Maybe you need to reinstall and make sure the extensions are included. – craniumonempty Jul 15 '14 at 03:19
  • Yeah sounds like issue with mysql installation. Make sure you are using mysqli extension rather than mysql as cranium has mentioned. – EternalHour Jul 15 '14 at 03:27
  • phpinfo shows an entry for PDO but shows _no value_ under PDO drivers. php_mbstring.dll is uncommented in my php.ini file and I've made sure it is in my C:\php\ext folder. I'm going to see if I can upload a copy of my php.ini file to see if there is anything wrong with that. How should I go about making sure I'm using mysqli INSTEAD OF mysql? (I had thought mysqli supplemented mysql...beginner's mistake?) – recoveringn00b Jul 15 '14 at 04:06
  • I highly recommend virtualised development environments. Check out Vagrant and any of the many LAMP style boxes available on github – Phil Jul 15 '14 at 04:26
  • @Phil That was putting too much between me and my programs...the interfaces all felt extraneous and unintuitive.:-/ – recoveringn00b Jul 16 '14 at 02:14
  • @All Going to try uninstalling and re-installing MySQL...will update! – recoveringn00b Jul 16 '14 at 02:15
  • @recoveringn00b I don't understand. With dev environment virtualisation, your *programs* stay on the host machine. – Phil Jul 16 '14 at 04:07
  • @Phil I mean that I was used to using PHP, MySQL, and phpmyadmin without the XAMP or WAMP interfaces I tried because I learned to use them on my grad school's system which had the individual components installed before I got there. Trying to install package-style bundles gives me a whole additional interface to work with--I think it was XAMP that used a client to access and administer the different components and WAMP gave me this whole page when I tried to pull up my localhost:8080 in my browser that added all this extraneous stuff that I had to interface with to get to my docroot and such. – recoveringn00b Jul 18 '14 at 02:31
  • @Phil It felt very clunky and extraneous to me and I learned how to work PHP and phpmyadmin without it, so I went back to trying to install the components individually. – recoveringn00b Jul 18 '14 at 02:32
  • @recoveringn00b So obviously you didn't even bother checking out what a virtualised environment would be. Vagrant would let you spin up a linux environment in VirtualBox, VMWare or AWS, pre-configured with Apache, MySQL and PHP (just like your grad school's system). This has nothing to do with installation packages like WAMP, XAMP, et al – Phil Jul 18 '14 at 04:23
  • @Phil I guess I got the terminology confused. As I say, I'm pretty new to all this and I'm teaching myself. In any case, I'm trying to figure out right now how I can get a copy of libmysql.dll and then I think that might give me a good chance at having this all straightened out. – recoveringn00b Jul 19 '14 at 04:44

1 Answers1

0

It seems like your php is installed under C:\PHP if you can get phpinfo() working that means php is running and apache is serving .php files properly.

Problem is your extensions are not loading edit php.ini and make sure you have extension_dir="C:\PHP\ext" set also make sure

extension=php_mysql.dll
extension=php_mysqli.dll
PoX
  • 1,229
  • 19
  • 32