Jump to content


Photo

mysql_connect function not responding?

phpmyadmin database mamp

  • Please log in to reply
4 replies to this topic

#1 doloreel

doloreel

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 29 April 2013 - 08:01 PM

First of all i'm new to this. 

 

the mysql_connect('localhost', 'root', '') always seems to run even when the values are wrong. 
I assume that something is wrong here? 

 

I am running MAMP.

 



#2 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,534 posts

Posted 29 April 2013 - 08:08 PM

the mysql_connect() statement will always run (assuming the function is defined.) if the connection fails, the function call will return a false value to the calling code. do you have any logic in your code to test if that function returns a false value?


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#3 doloreel

doloreel

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 29 April 2013 - 08:30 PM

Ah ok. No i dont have any logic to test if its false.



#4 doloreel

doloreel

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 29 April 2013 - 08:41 PM

this is my code now, it just returns 'could not connect' although phpmyadmin is running and i have input everything correctly. any ideas?

<?php
	if (!@mysql_connect('localhost', 'root', '') || !@mysql_select_db('a_database')) {
		die('could not connect');
	} 
?>




#5 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,534 posts

Posted 29 April 2013 - 08:50 PM

echoing mysql_error() or using mysql_error() in the die() statement will tell you why the connect/select_db statement is failing.


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com