Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 107,708 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,129 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



MySQL connect

 
Reply to this topicStart new topic

MySQL connect, PHP Mysql connect not working

woodjom
post 24 Jul, 2008 - 07:39 PM
Post #1


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 43



Thanked 1 times
My Contributions


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.

php

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 Jul, 2008 - 07:50 PM
User is offlineProfile CardPM

Go to the top of the page


no2pencil
post 24 Jul, 2008 - 07:43 PM
Post #2


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 4,846



Thanked 27 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


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
User is online!Profile CardPM

Go to the top of the page

woodjom
post 25 Jul, 2008 - 05:41 AM
Post #3


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 43



Thanked 1 times
My Contributions


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 Jul, 2008 - 05:41 AM
User is offlineProfile CardPM

Go to the top of the page

woodjom
post 25 Jul, 2008 - 06:07 AM
Post #4


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 43



Thanked 1 times
My Contributions


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:
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:
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 Jul, 2008 - 06:07 AM
User is offlineProfile CardPM

Go to the top of the page

woodjom
post 25 Jul, 2008 - 06:20 AM
Post #5


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 43



Thanked 1 times
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

woodjom
post 25 Jul, 2008 - 06:39 AM
Post #6


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 43



Thanked 1 times
My Contributions


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?
User is offlineProfile CardPM

Go to the top of the page

akozlik
post 25 Jul, 2008 - 07:13 AM
Post #7


D.I.C Regular

Group Icon
Joined: 25 Feb, 2008
Posts: 395



Thanked 15 times

Dream Kudos: 700
My Contributions


What do you get if you echo out the values of the variables right before attempting to connect?
User is offlineProfile CardPM

Go to the top of the page

woodjom
post 25 Jul, 2008 - 07:29 AM
Post #8


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 43



Thanked 1 times
My Contributions


either 0 or nothing (ie no value/blank)
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/30/08 02:52AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month