mars9807 Posted September 19, 2012 Share Posted September 19, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/ Share on other sites More sharing options...
Jessica Posted September 19, 2012 Share Posted September 19, 2012 I think you have your file names backwards, because otherwise your file is including itself. Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379332 Share on other sites More sharing options...
mars9807 Posted September 19, 2012 Author Share Posted September 19, 2012 Yes, you are correct - misspelling in my post, but the actual script is Ok. s/b include ("/Web/include_path/db_inc.php"); Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379338 Share on other sites More sharing options...
Jessica Posted September 19, 2012 Share Posted September 19, 2012 After the include, echo the three variables. Are they correct? Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379344 Share on other sites More sharing options...
mars9807 Posted September 19, 2012 Author Share Posted September 19, 2012 No, they are null. this leads me to believe the path to the include is incorrect, but it isn't. Linux permissions for this include file are the same as all my others... Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379350 Share on other sites More sharing options...
Jessica Posted September 19, 2012 Share Posted September 19, 2012 What if you echo them in the include? Are either of these part of a class or function? Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379352 Share on other sites More sharing options...
mikosiko Posted September 19, 2012 Share Posted September 19, 2012 maybe to obvious but, the folder name is "Web" or "web" Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379354 Share on other sites More sharing options...
mars9807 Posted September 19, 2012 Author Share Posted September 19, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379363 Share on other sites More sharing options...
Jessica Posted September 19, 2012 Share Posted September 19, 2012 ? Are you saying the actual PHP is shown? Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379367 Share on other sites More sharing options...
mars9807 Posted September 19, 2012 Author Share Posted September 19, 2012 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' Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379395 Share on other sites More sharing options...
kicken Posted September 19, 2012 Share Posted September 19, 2012 Did you forget your opening <?php tag in the include file? Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379396 Share on other sites More sharing options...
mars9807 Posted September 19, 2012 Author Share Posted September 19, 2012 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379412 Share on other sites More sharing options...
Jessica Posted September 19, 2012 Share Posted September 19, 2012 Be sure to use <?php not just <? Quote Link to comment https://forums.phpfreaks.com/topic/268567-includeconnection-issue-desperate/#findComment-1379416 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.