A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearConnecting to MySQL database with PHP - page 1
User InfoPosts
Connecting to MySQL database with PHP#1
I have this little function do connect to a MySQL database:

function connectSugarCRM()
{
$connectorSugarCRM = mysql_connect ("localhost", "123", "123")
or die ("Connection failed");
mysql_select_db("sugar5") or die ("Failed attempt to connect to database");
return $connectorSugarCRM;
}


And then, to run a query, I(m doing something like this, but I allways get an "PHP Fatal error: Cannot redeclare connectSugarCRM() (previously declared in ...", which points to the definition of my function "connectSugarCRM" (line 1).

$ExecuteSQL = mysql_query ($sqlSTR, connectSugarCRM()) or die ("Query Failed!");


What is wrong with my code?
Thanks

posted date: 2009-04-07 05:42:00


Re: Connecting to MySQL database with PHP#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-07 05:42:01


Re: Connecting to MySQL database with PHP#3
First, search all of your code for (function connectSugarCRM()( and make sure it appears once and only once. If it(s there more than once, that(s your problem.Otherwise, try changing your query line to this:$sugarConnection = connectSugarCRM();$ExecuteSQL = mysql_query($sqlSTR, $sugarConnection) or die ("Query Failed!");And in the future, the line numbers and full error messages are really helpful for debugging this stuff.

posted date: 2009-04-07 05:55:00


Re: Connecting to MySQL database with PHP#4
Always use include_once or require_once when including other files.

posted date: 2009-04-07 05:59:00


Re: Connecting to MySQL database with PHP#5
Scott: 1-I'm totally sure that the function is only defined once and there is no recursive includes. 2-I need to identify the database connector, because I'm using more than one database in the same procedure. 3 - Line Error - fixed

posted date: 2009-04-07 06:03:00


Re: Connecting to MySQL database with PHP#6
I've changed my code suggestion to handle your #2. It really looks like that function is defined or included more than once. Maybe you can post more of your code so we can check for multiple includes. I've been "totally sure" and wrong so many times...

posted date: 2009-04-07 07:54:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.