|Connecting to MySQL database with PHP||#1|
I have this little function do connect to a MySQL database:
$connectorSugarCRM = mysql_connect ("localhost", "123", "123")
or die ("Connection failed");
mysql_select_db("sugar5") or die ("Failed attempt to connect to database");
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?
posted date: 2009-04-07 05:42:00
|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 »|