PHP and MySQL not communicating

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I have come to the conclusion that my PHP installation and my MySQL installation are not getting along; I’m working on making my first web page that uses MySQL for content, but after two days, man pages, online documentation, and dozens of tutorials, I just can’t get the PHP/MySQL part to work. I have an established home web server (I am the only admin/user) that runs Apache and hosts my web pages. I have MySQL installed, and was able to create and query a database through Terminal. I have PHP installed, and can use echo to print text to the document. When I work with MySQL however, everything changes…

I have a page that contains initialization stuff in . contains a few paragraphs of hardcoded HTML and then PHP code to access MySQL. When I first loaded the page, all that resulted was a blank page. I commented out the PHP section and reloaded to confirm that the plain HTML still worked, which it did. Therefore, some part of PHP was keeping any of the page from ever loading.

To begin troubleshooting my code, I left all of the PHP code commented except the following code for the server connection, which is adapted from several different tutorials:

PHP is working

"); $ses = mysql_connect("localhost","username","password"); if(!$ses){ echo("

Connection to content server failed.

"); exit(); } echo("

Database Connected

"); ?>

When the page is loaded, the beginning HTML loads in addition to a paragraph reading “PHP is working” but neither the failure or success message appear. I removed the If structure from the code - so that only two echos and the mysql_connect remained – and got the same result.

It seems that the mysql_connect feature is causing the server to stop loading the code when it is run, but I’m out of ideas for how to fix it. For the record: I’ve modified the php.ini file to include the “connection = msql.so” line, and I’m using MySQL 5.5, Apache 2.2.22, PHP 5.3.10, Ubuntu 12.04. Also, both my router and modem have been configured to forward port 3306 to the server – though I don’t see how that should be necessary – and my MySQL username and password have been triple checked and are identical to the ones that I use successfully in Terminal.

What am I missing?

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.