Jump to content

Recommended Posts

Hello!

 

I have a standard connection include file that I use for all my MySQL db connects.  One for each app.  It looks like this:

 

db_inc.php 

 

//(stores the db connectivity info)

 

$db_server="server";

$db_username="username";

$db_password="password";

$db_name="dbname";

 

-- end

 

ea_inc.php  (code to include the above)

 

  $db_server='';

  $db_username='';

  $db_password='';

  $db_name='';

  // Hide MySQL password in non-web directory

  include ("/Web/include_path/ea_inc.php");

  mysql_connect ($db_server,$db_username,$db_password)

    or die ("Error: Unable to connect to database");

.

.

 

 

---end

 

I just created a new app and corresponding include file.  For some bizarre reason, it will not connect to the db UNLESS I hard code the login, pwd, db, etc. into the variable names in the ea_inc.php file.  I have retyped, checked spellings, etc.  It is actually finding the include file because it echoes to the screen with the correct information plugged in.  Has anyone experienced anything like this?  Part of me thinks it is something really stupid, but for the life of me, I can't figure this out and have been pulling my hair out for hours.

 

When I run the script, this is what I get:

 

$db_server="server"; $db_username="username"; $db_password="password"; $db_name="dbname";

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

 

The script seems to find the server, user, pwd, and db name values in the include file.  Again, if I hardcode the variable content in ea_inc.php, it works fine.  Any advice is much appreciated! 

Link to comment
https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/
Share on other sites

Yes, the path is correct with a 'Web' instead of 'web'.  When I echo the variables to the screen in the include (it's an include and not a class) I get:

 

echo "

".db_server is: " . $db_server;

echo "

".db_username is: " . $db_username;

 

Hmmmm

Yes, that's correct:

 

$db_server = "servername"; $db_username = "username"; $db_password = "password"; $db_name = "dbname"; echo "

".db_server is: " . $db_server; echo "

".db_username is: " . $db_username;

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

You are going to think me a total idiot, but YES that was the problem!  However, none of my other db connect includes have contain that either and work just fine.  I have at least 10 others without the beginning <? or ending ?>.  As you can imagine, I'm going to update them ALL right now. 

 

I'm not sure that I would have figured this out due to the fact that the others worked without the <? ?>.  I needed outside eyes.

 

I cannot thank you enough!!!  Many, many thanks!!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.