simpleorchid Posted November 19, 2012 Share Posted November 19, 2012 (edited) 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 November 19, 2012 by Pikachu2000 Spammy-looking links removed. Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/ Share on other sites More sharing options...
jazzman1 Posted November 19, 2012 Share Posted November 19, 2012 (edited) I'm not a windows user, but...... you should check the current status of your database! How to open them - Windows button+R and type: services.msc Edited November 19, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1393493 Share on other sites More sharing options...
simpleorchid Posted November 20, 2012 Author Share Posted November 20, 2012 Well, I checked it. And For mysql it says that it "started" (status) and is automatic (startup type). Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1393687 Share on other sites More sharing options...
Christian F. Posted November 20, 2012 Share Posted November 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1393691 Share on other sites More sharing options...
jazzman1 Posted November 20, 2012 Share Posted November 20, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1393806 Share on other sites More sharing options...
Muddy_Funster Posted November 20, 2012 Share Posted November 20, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1393812 Share on other sites More sharing options...
simpleorchid Posted November 21, 2012 Author Share Posted November 21, 2012 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1393944 Share on other sites More sharing options...
jazzman1 Posted November 21, 2012 Share Posted November 21, 2012 I'm thinking that you want to make a mock of windows Why don't you install a wamp or xampp server? Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1393950 Share on other sites More sharing options...
simpleorchid Posted November 21, 2012 Author Share Posted November 21, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1393957 Share on other sites More sharing options...
Muddy_Funster Posted November 21, 2012 Share Posted November 21, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1394012 Share on other sites More sharing options...
simpleorchid Posted November 22, 2012 Author Share Posted November 22, 2012 Thanks a lot @Muddy_Funster. Yes it is my ignorance that telnet is hidden and have to be turned on if one needs it. I think I should go by your advice of using XAMPP. So I should uninstall all of mysql, apache server, and php. Once again thank you all who tried to help me. Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1394280 Share on other sites More sharing options...
txmedic03 Posted November 24, 2012 Share Posted November 24, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1394707 Share on other sites More sharing options...
simpleorchid Posted November 25, 2012 Author Share Posted November 25, 2012 txmedic03, Thanks for the info. You have given me some insights. Thanks once again. Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1394890 Share on other sites More sharing options...
txmedic03 Posted November 25, 2012 Share Posted November 25, 2012 Glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/270894-connection-problem-between-php-and-mysql/#findComment-1394921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.