Jump to content

Connection Problem Between Php And Mysql


simpleorchid

Recommended Posts

Hi, I am new here and I do not know where to put my questions and problems regarding php and mysql. I recently installed php 5 and mysql 5.5 and apache web server individually on my windows 7 operating system. I also intalled netbean ide. So far, my php file will work without database. For example <?php echo phpinfo(); ?> will work. But when I try to connect my php file with the database , it fails. In my netbean ide, I tried to test connection but it fails and shows the following errors......

 

Cannot establish a connection to jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull using com.mysql.jdbc.Driver (Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

 

 

My server host name is localhost.

server port number is 3306

username is root

and password ="".

 

Could anyone identify the problems I am having? Another question .... Should mysql be installed inside the web server folder or separate location?

 

I usually see my database in the mysql command line console. so i think it has to do with the connection problem. Any idea?

 

Thanks in advance.

 

Zac

Edited by Pikachu2000
Spammy-looking links removed.
Link to comment
Share on other sites

Make sure that your firewall isn't blocking communications with the server on the localhost (127.0.0.1) interface, alternatively make sure that the mysql socket file (if that is used on Windows) exists where PHP/Netbeans expects it.

I don't think so, that the firewall is blocking communication with server on the localhost.

@simpleorchid, did you try to connect to database using a mysql console?

Exemple:

mysql -h localhost -u root -p

Link to comment
Share on other sites

I don't think so, that the firewall is blocking communication with server on the localhost.

@simpleorchid, did you try to connect to database using a mysql console?

Exemple:

mysql -h localhost -u root -p

 

Yes i did try this (mysql console). And there was no problem with it.

 

**************************************

 

 

you can try to telnet to your localhost on port 3306 to see if the firewall, or any other problem is blocking it.

 

and NO your database storage files should most deffinately NOT be in your web folder

 

Well I am on window 7, that cmd telnet is not available. it is only available on Windows xp and 2000... see http://www.computerhope.com/telnethl.htm

 

***********************************

 

I have tried turning off the firewall for 15 mins and repeated the process. But to my surprise, nothing changes.

 

here is my script for database connection.

 

 

<?php

$dsn = 'mysql:host=localhost;dbname=my_guitar_shop1';

$username = 'root';

$password = '';

 

try {

$db = new PDO($dsn, $username, $password);

} catch (PDOException $e) {

$error_message = $e->getMessage();

include('database_error.php');

exit();

}

?>

Link to comment
Share on other sites

The reason why i installed individually is that in the end (read as in future) when I make websites (for clients) in the future, I may have to deploy them and think that i have to install the requirement individually. So I thought that this will teach me how to do it and make preparation. I hope you know what I mean. Now I am in learning stage.

Link to comment
Share on other sites

Windows 7 does have telnet, you just need to turn it in the the programs/features windows-features section.

 

As for deploying in a proffessional sense - you do know how much licensing cost is envolved to run windows as web server? If you want to get a feel for production level hosting get virtualBox and download one of the server distros of Linux - I think CentOS currently has the highest number of webfacing servers. Over and above that XAMPP is a much easier tool for developing on windows machines than having to manage the individual components on their own.

Link to comment
Share on other sites

I have had bad experience with running CentOS. It is a pretty solid distro and all, but some software does not build well on it. Ubuntu 12.04 minimal is LTS now and all the services I've installed on it were a lot less painful on Ubuntu than CentOS. When you are installing the server software and the developers list installation instructions for Windows, Mac OS x, Fedora, Ubuntu, SuSE and a handful of other linux distros then mention CentOS and say the software doesn't build well on CentOS, I take it as a sign that I should know when I'm beat and setup an Ubuntu box. If all you are doing is a basic web server with MySQL and PHP then CentOS will definitely work, but check into any and all services and which distro they run best on before you pick the one you are going to work with. VirtualBox is a great way to pick one and build up the server without needing an actual server or having to wipe out a computer to pull it off.

 

Now as to your requirement for installing all these services individually...it depends on if you are doing dedicated managed or unmanaged hosts. If you are doing a shared level hosting reseller package then you wouldn't have to install any services at all (actually you wouldn't even have the option). If you do unmanaged dedicated servers then you provision the box with the specified OS with nothing more than OS and SSH and wish them the best of luck. If you are providing managed dedicated or VPS (Virtual Private Server) then you would likely be installing MySQL, Apache and PHP (LAMP - Linux Apache MySQL PHP). If your server of choice were Ubuntu you'd simply do apt-get install <packages> then tweak the configs and you are done. I'd just about be willing to bet that you wouldn't be doing a whole lot of windows servers, so installation on windows won't help you much and even if you do run a lot of windows servers, the majority of the time you'll find your customers are looking for Apache, MySQL and PHP or having the additional features won't hurt so...(WAMP - Windows Apache MySQL PHP) There is an installer package for windows which includes all of them and is quick and easy to setup.

 

Bottom line: You put in some extra work you didn't really have to. It's great that you want to understand how to set everything up so you can better service clients, but no sense re-inventing the wheel.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.