5 Replies - 1641 Views - Last Post: 12 December 2010 - 07:21 AM Rate Topic: -----

#1 Codin  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 45
  • Joined: 31-March 10

I am getting warnings when trying to connect to database

Posted 11 December 2010 - 06:57 PM

I keep getting these errors or warnings when I try to connect to my database on localhost.
Warning: mysqli_connect() [function.mysqli-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Here is the code I used to try to connect.
 <?php
		$link = mysqli_connect('localhost', 'root', 'Mypassword');
		if (!$link)
		{
			$output = 'Unable to connect to the database server.';
			include 'output.html.php';
			exit();
		}
		
		if (!mysqli_set_charset($link, 'utf8'))
		{
			$output = 'Unable to set database connection encoding.';
			include 'output.html.php';
			exit();
		}
		
		if (!mysqli_select_db($link, 'ijdb'))
		{
			$output = 'Unable to locate the joke database.';
			include 'output.html.php';
			exit();
		}
		
		$output = 'Database connection established.';
		include 'output.html.php';
?>

and the rest of the html code.
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
              <html xmlns="http://www.w3.org/1999/xhtml"> 
              <head>
                <title>PHP Output</title>
               <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
               
               </head>

     
              <body>
                <p>
                  <?php echo $output; ?>
                </p>
            
              </body>
              </html>

All help greatly appreciated.Thank you in advance

Is This A Good Question/Topic? 0
  • +

Replies To: I am getting warnings when trying to connect to database

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2999
  • View blog
  • Posts: 10,383
  • Joined: 08-August 08

Re: I am getting warnings when trying to connect to database

Posted 11 December 2010 - 08:25 PM

Are you sure the mysqli server is running?
Was This Post Helpful? 1
  • +
  • -

#3 Codin  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 45
  • Joined: 31-March 10

Re: I am getting warnings when trying to connect to database

Posted 11 December 2010 - 09:01 PM

View PostCTphpnwb, on 11 December 2010 - 07:25 PM, said:

Are you sure the mysqli server is running?



By is the mysqli server running do you mean did I un-comment the extension mysqli in my php.ini because I did remove the; when I set it up. I thought that was the problem also but it wasn't. If you have any more suggest I would appreciate them. Thank you a great question. Codin
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,250
  • Joined: 08-June 10

Re: I am getting warnings when trying to connect to database

Posted 12 December 2010 - 02:23 AM

do you have a MySQL server (the database) running?

This post has been edited by Dormilich: 12 December 2010 - 02:23 AM

Was This Post Helpful? 2
  • +
  • -

#5 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2999
  • View blog
  • Posts: 10,383
  • Joined: 08-August 08

Re: I am getting warnings when trying to connect to database

Posted 12 December 2010 - 07:09 AM

And is mysqli support enabled?

See attached screen shot from php_info on my system.

Attached image(s)

  • Attached Image

Was This Post Helpful? 1
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: I am getting warnings when trying to connect to database

Posted 12 December 2010 - 07:21 AM

And is your software firewall allowing connections on port 3306?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1