MySQL connect

PHP Mysql connect not working

Page 1 of 1

7 Replies - 1728 Views - Last Post: 25 July 2008 - 07:29 AM Rate Topic: -----

#1 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

MySQL connect

Post icon  Posted 24 July 2008 - 07:39 PM

Hey guyz/galz,
Just threw this mysql_connect function together while looking at the PHP.net site. In theory it should work by all syntax they supply from the site but i am unable to get a good connection. It gives me this error message....i even put in some debug tracers but they never evaluate.


Quote

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /homepages/3/d226734254/htdocs/test/pbbg5/db.php on line 13
The connection to the database is currently down for maintenance, please try again after awhile!


here is the code i am trying to evaluate.

function connectDb()
     {
         $dbserver &= ":3307";
         global $dbconnect;
         if ($dbconnect){
             return $dbconnect;
         }
         echo "$dbserver";
         echo "$dbuid";
         echo "$dbpwd";
         echo "$dbname";
         $dbconnect = mysql_connect($dbserver, $dbuid, $dbpwd, TRUE);  //line 13 in my editor
         if (!$dbconnect){
             echo "The connection to the database is currently down for maintenance, please try again after awhile!";
             return $dbconnect;
         }
         echo "db.php:connectDB |Connection made!";
         mysql_select_db($dbname, $dbconnect) or die("The database is currently unavailable, please be patient");
         echo "db.php:connectDB |Database Connected!";
         return $dbconnect;
     }


I have done a google on it but most everything relies on the fact that i am running my own server or it is Windows based. My server is Unix and is hosted on 1and1....this code page is located on their server so shouldnt be an issue of accessing the sql server.

This post has been edited by woodjom: 24 July 2008 - 07:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: MySQL connect

#2 no2pencil  Icon User is online

  • Dic Head
  • member icon

Reputation: 5175
  • View blog
  • Posts: 26,868
  • Joined: 10-May 07

Re: MySQL connect

Posted 24 July 2008 - 07:43 PM

Can you verify that mysql is in fact running by connecting to it via command line?

Also :

If this is a Linux/Unix system, you can check for it with ps aux | grep mysql
If this is a Windows system, check the task manager via taskmgr
Was This Post Helpful? 0
  • +
  • -

#3 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: MySQL connect

Posted 25 July 2008 - 05:41 AM

this is a Unix system....i can verify the MySQL database cause i am posting data into the tables at the same time i developing the PHP backend. I have done this before with ASP but PHP is kinda new for me, so taking it slow. Checked other PHP sites i have posted to my domain and they have alot of error, validation, and value checking before the actual mysql_connect function and they work fine. I would like to try and KISS.

KISS:
Keep
It
Simple
Stupid

This post has been edited by woodjom: 25 July 2008 - 05:41 AM

Was This Post Helpful? 0
  • +
  • -

#4 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: MySQL connect

Posted 25 July 2008 - 06:07 AM

changed some code around in my db.php file and got a different error.

Quote

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2) in /homepages/3/d226734254/htdocs/test/pbbg5/db.php on line 11
Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2)


index.php:
include('config.php');
     include('db.php');
//     include('gsystem.php');

     echo "Alot of something ";
     echo "$dbconnect";
     echo " here";
     echo '<br/>';
     $conn = connectdb();
     echo "$echo";


db.php:
include('config.php');
	 
	 function connectDb()
	 {
		 $dbconnect = 1;

		 echo "$dbserver";
		 echo "$dbconnect";
		 $dbconnect = mysql_connect($dbserver, $dbuid, $dbpwd) or die(mysql_error());
		 echo "passed the connect phase";
/*		 if (!$dbconnect){
			 echo "The connection to the database is currently down for maintenance, please try again after awhile!";
			 return $dbconnect;
		 }*/
		 echo "db.php:connectDB |Connection made!";
		 mysql_select_db($dbname, $dbconnect) or die("The database is currently unavailable, please be patient");
		 echo "db.php:connectDB |Database Connected!";
		 return $dbconnect;
	 }

This post has been edited by woodjom: 25 July 2008 - 06:07 AM

Was This Post Helpful? 0
  • +
  • -

#5 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: MySQL connect

Posted 25 July 2008 - 06:20 AM

why is it that when i click on the link [function.mysql-connect] it points to a page in the directory that is not there? points to the site address location/function.mysql-connect file.
Was This Post Helpful? 0
  • +
  • -

#6 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: MySQL connect

Posted 25 July 2008 - 06:39 AM

Now when i hard code the server, uid, pwd into the connect function.....it works...but when i put the variable reference from config.php, it does not work and throws the error...is there something i am doing with the include function?
Was This Post Helpful? 0
  • +
  • -

#7 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: MySQL connect

Posted 25 July 2008 - 07:13 AM

What do you get if you echo out the values of the variables right before attempting to connect?
Was This Post Helpful? 0
  • +
  • -

#8 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: MySQL connect

Posted 25 July 2008 - 07:29 AM

either 0 or nothing (ie no value/blank)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1