944,196 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 358
  • PHP RSS
Oct 11th, 2009
0

Database function fail

Expand Post »
PHP Syntax (Toggle Plain Text)
  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.
Similar Threads
grr
Reputation Points: 10
Solved Threads: 0
Light Poster
grr is offline Offline
29 posts
since Jun 2008
Oct 11th, 2009
0
Re: Database function fail
From the PHP Documentation:
Quote ...
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.
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Oct 12th, 2009
0
Re: Database function fail
I guess this have the second argument(connection) missing:
php Syntax (Toggle Plain Text)
  1. mysql_select_db($db_name)
try something like this:
php Syntax (Toggle Plain Text)
  1. $conn = mysql_connect($db_host, $db_user, $db_pass);
  2. mysql_select_db($db_name, $conn);
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
Next Thread in PHP Forum Timeline: Export .php to pdf(with table)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC