Database function fail

Reply

Join Date: Jun 2008
Posts: 29
Reputation: grr is an unknown quantity at this point 
Solved Threads: 0
grr grr is offline Offline
Light Poster

Database function fail

 
0
  #1
Oct 11th, 2009
  1. function fafaconnect($db_host, $db_user, $db_pass, $db_name) {
  2. @mysql_connect($db_host, $db_user, $db_pass);
  3. @mysql_select_db($db_name);
  4. }
  5.  
  6. if ($link = @mysql_connect("localhost", "admin", "pass")) {
  7. echo "pass-";
  8. } else {
  9. echo "fail-";
  10. }
  11. if ($select = @mysql_select_db("zushee")) {
  12. echo "pass-";
  13. } else {
  14. echo "fail-";
  15. }
  16.  
  17. if ($newlink = fafaconnect("localhost", "admin", "pass", "zushee")) {
  18. echo "pass";
  19. } else {
  20. echo "fail";
  21. }


This returns pass-pass-fail. Any ideas?
Last edited by grr; Oct 11th, 2009 at 10:04 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 801
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark
 
0
  #2
Oct 11th, 2009
From the PHP Documentation:
Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as Runtime Configuration in your PHP configuration and leave the server field blank.
Try changing localhost to 127.0.0.1 and see if this fixes your problem. If not, try echo'ing mysql_error() instead of "fail" as this will give you more details as to why your connect call is failing.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,439
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso
 
0
  #3
Oct 12th, 2009
I guess this have the second argument(connection) missing:
  1. mysql_select_db($db_name)
try something like this:
  1. $conn = mysql_connect($db_host, $db_user, $db_pass);
  2. mysql_select_db($db_name, $conn);
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC