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 30 April 2013 - 01:01 AM

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

    Staff Alumni

  • Staff Alumni
  • 3,192 posts

Posted 30 April 2013 - 01:08 AM

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 30 April 2013 - 01:30 AM

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



#4 doloreel

doloreel

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 30 April 2013 - 01:41 AM

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

    Staff Alumni

  • Staff Alumni
  • 3,192 posts

Posted 30 April 2013 - 01:50 AM

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