yrstruly Posted June 3, 2013 Share Posted June 3, 2013 (edited) Im trying to connect to mysql database and get the folllowing error: Could not connect to MySQL:No connection could be made because the target machine actively refused it. . Im running this code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Connect to MySQL</title></head><body><?php // Script 12.2 - mysql_connect.php #2/* This script connects to the MySQL server. */ // Attempt to connect to MySQL and print out messages:if ($dbc = @mysql_connect('localhost', '', '')) { print '<p>Successfully connected to MySQL!</p>'; mysql_close($dbc); // Close the connection. } else { print '<p style="color: red;">Could not connect to MySQL:<br />' . mysql_error() . '.</p>'; } ?></body></html>Also dont work when i run it like:if ($dbc = mysql_connect('localhost','username', 'password')) { Im using Xammp Edited June 3, 2013 by yrstruly Link to comment Share on other sites More sharing options...
birbal Posted June 3, 2013 Share Posted June 3, 2013 Check for mysql error using http://php.net/mysql_error. Be sure of your username and password Link to comment Share on other sites More sharing options...
justsomeguy Posted June 3, 2013 Share Posted June 3, 2013 It sounds like you don't have MySQL installed or running, or you have a firewall blocking port 3306 on your machine. Link to comment Share on other sites More sharing options...
yrstruly Posted June 5, 2013 Author Share Posted June 5, 2013 I have the following code and i cant connect. usually i can if i leave out the username and password or type it in, but some how i just cant get this one right now. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Connect to MySQL</title></head><body><?php // Script 12.1 - mysql_connect.php/* This script connects to the MySQL server. */// Attempt to connect to MySQL and print out messages:if ($dbc = mysql_connect('localhost', 'b17_13305510', '')) { print '<p>Successfully connected to MySQL!</p>'; mysql_close($dbc); // Close the connection.} else { print '<p style="color: red;">Could not connect to MySQL.</p>';}?></body></html> Hers the login details and i replace it int he file as follows Your URL: http://yrstruly.byethost17.com or http://www.yrstruly.byethost17.com FTP Server : ftp.byethost17.com FTP Login : b17_13305510 FTP Password : ****** MySQL Database Name: MUST CREATE IN CPANEL MySQL Username : b17_13305510 MySQL Password : ****** MySQL Server: SEE THE CPANEL Link to comment Share on other sites More sharing options...
justsomeguy Posted June 5, 2013 Share Posted June 5, 2013 If it can't connect then either the server name, username, or password is wrong. You can get the error message with mysql_error. Link to comment Share on other sites More sharing options...
guruparthi Posted October 27, 2014 Share Posted October 27, 2014 (edited) Try this <?php mysql_connect('localhost','root','') or die('Cannot connect mysql server'); mysql_select_db('new') or die('cannot connect database');?> This is the concept for connect database. Edited October 27, 2014 by guruparthi Advertising Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now