Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_connect stopping php from printing? 1

Status
Not open for further replies.

PinkeyNBrain

IS-IT--Management
Dec 12, 2006
279
US
Not 100% sure just where the source of the problem is here:

Setup:
- OS: WinXP SP3
- Loaded apache http server 2.2 - appears to test ok
- Loaded MySQL - generated tables - all is ok
- Loaded php - generic 'hello world' works (hello.php) under command prompt
- hello.php works as web page under apache

So far so good. Next I generated a simple mysql_connect / mysql_select_db / mysql_query sequence under php. The program works as expected under the command prompt. If I try to run it under apache, output stops as soon as I use the mysql_connect. Consider
Code:
  print "pre connect\n"; // prints normally
  mysql_connect($host, $user, $passwd) ;
  print "post connect\n" ; // This prints under cmd but not under apache
The very first time I open a browser and attempt to load the page, I'll get a HTML 500 error. If I press reload, I'll see the 'pre connect' but not the 'post connect'.

Found one example of a user who corrected a similar issue by ensuring "$user" was in the administrators group for the PC. Tried that but it didn't help. Also found references stating to dump phpinfo() and make sure the mysql extensions are loaded. Not being a heavey hitter in this, I wasn't sure what to look for that indicated these extensions were loaded. Not sure if the fact that this works under the cmd prompt has any relevence on this.

If this belongs under another forum, sorry and let me know.
 
Try asking mysql for some more information:

Code:
  mysql_connect($host, $user, $passwd)[red]or die(mysql_error())[/red] ;

You should also make sure display_errors is on in PHP.ini, and that error_reporting is set to E_ALL.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Vacunita - Good call on the display_errors, it pointed out that indeed mysql_connect was not defined. (error_reporting = E_ALL already in place) Thanks.

Found "extension_dir =" it was set to a relative path, changed to direct path. By chance I found out the following
Code:
print "1" ;
($sql_conn = mysql_connect($host, $user, $passwd)) or die(mysql_error()) ;
print "2" ;
mysql_close($sql_conn) ; // for now ignore that this is not needed
print "3" ;
The above snippet will generate the "IE cannot display web page" error .. nothing shows up. However this snippet
Code:
print "1" ;
//($sql_conn = mysql_connect($host, $user, $passwd)) or die(mysql_error()) ;
print "2" ;
mysql_close($sql_conn) ;
print "3" ;
Results in the error
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource
Which is curious as it's telling me that the MySQL extensions are loaded otherwise mysql_close would error as an undefined function. I've been staring at this long enough that I'll start to ramble on if I don't wait for more input. Thanks for the help so far.
 
Sounds like there may still be some config error in the PHP setup.

Create a new PHP page and just stick the following in it and run it from a browser:

Code:
<?PHP
phpinfo();
?>

If it successfully runs you should a page with lots of info for your PHP page. If not, there's some issue with the PHP settings.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Yes - I've successfully done that one. I've seen other postings indicating that I should run it and verify that the mysql extensions are loaded. In the php.ini I can find
Code:
extension=php_mysql.dll
extension=php_mysqli.dll
For grins I tried reversing the two to see if it made any difference (it didn't). Thinking about configuring - in the httpd.conf I have the following lines
Code:
LoadModule php5_module modules_php/php5apache2_2.dll
AddType application/x-httpd-php .php
When I expanded the .zip file, under the modules_php directory are also:
php5apache.dll
php5apache2.dll
php5apache2_2.dll
php5apache2_2_filter.dll
php5apache2_filter.dll
php5apache_hooks.dll
php5isapi.dll
php5nsapi.dll
php5ts.dll
None of these are brought in through LoadModule (except php5apache2_2.dll) - I've tried php5apache.dll and php5apache2.dll and even though the file is there, I get an error message saying the module doesn't exist. If I load php5apache2_2.dll first then try to load php5apache2.dll afterward, I'll see "php5_module already loaded skipping" - so if one of these other modules has what I need, I'm not doing something right to make it work.

Can you suggest what I should look for in the phpinfo() output for verification?
 
Do you have the PHPIniDir directive in Apache's http.conf pointing to the right location for the PHP.ini in use?

Also you have restarted Apache after each of these changes right?



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Couldn't find anything in httpd.conf that referenced PHPIniDir. However I tried the following test: I commented out extension=php_mysql.dll and extension=php_mysqli.dll (restarted apache) and tried the program that only called mysql_close - and I get an error message that mysql_close is not defined. I uncommented the two extensions, restarted apache, and retried the program (i.e. web page) - Now I'm back to the error that I'm calling mysql_close with an invalid argument. This would make me want to believe that even though I'm not finding an obvious reference to php.ini in the httpd.conf, the php.ini file is being referenced.

I appreciate your help and if you happen to have any more “did you try xxxx” I’m way open for them. In the mean time, I’m going to try and reinstall the three progs paying close attention to anything mysql’ish.
 
Now I'm back to the error that I'm calling mysql_close with an invalid argument

That's an expected error if you have your mysql_connect line commented out.

The real problem is if you get the Page cannot be displayed error when its not commented out.

The phpini() function should tell you which PHP.ini is being used. From there you should be able to determine if its the one you are changing or not.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Output from phpinfo()
Loaded Configuration File C:\usr\local\Apache\php.ini
Scan this dir for additional .ini files (none)
additional .ini files parsed (none)

and I am indeed changing the php.ini file listed above. As for the mysql_close() giving me the 'bad argument' error, I'm using this to tell me that apache is recognizing mysql in some fashion or another (by way of it's lack of a undefined function error). Didn't get a phpini() function to work as posted above - will presume typo.

On a lark, I also tried 'root' for the user and still no success.
 
Yes, that seems to be o.k. Its loaded the dlls for mysql so it can access its functions. Since no connection has been made, there is no connection handle in the $sql_conn variable, hence not a valid mysql resource.

The more intriguing problem is the undisplayable page when the mysql_connect is not commented out which now should work.

I think maybe checking Apache's Log files may yield some answers of why its failing.

The phpini() function was a mistake yes, I meant phpinfo().

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Whoo - Hoo found it. Reviewing the log files finally make the link. The log file presented
child process exited with status 3221225477
Looking up that error message gave

[URL unfurl="true" said:
http://www.java-samples.com/showtutorial.php?tutorialid=1050[/URL]]If you are getting this error, you are probably trying to use Apache, MySQL and PHP in a windows system. Just do this simple step to solve this issue.

It is quite frustrating to see that all your PHP pages suddenly doesn't seem to work. If you check your Apache log file you will see this error: Parent: child process exited with status 3221225477 -- Restarting

Don't worry just goto the PHP installation folder and look for libmysql.dll file.

Just copy this file and save it to your windows\system32 folder.

Now restart MySQL and Apache servers.

Everything should be fine now and all your PHP pages will work as normal.
Vacunita - thanks for keeping me looking in the right places. Your persistance in working with a potential lost cause is worth a star.
 
Glad you finally sorted it out.

If you have other PHP related questions try the forum434.
I also hang around there.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top