Cannot redeclare foo() error – PHP

  php

Q(Question):

Hello, I got message:
Fatal error: Cannot redeclare sqlconnect() (previously declared in E:\Program Files\Apache Group\Apache2\htdocs\openemr-2.9.0\library\sql.inc:33) in E:\program files\apache group\Apache2\htdocs\openemr-2.9.0\library\sql.inc on line 36

File sql.inc:

<?php
...
function sqlConnect($login,$pass,$dbase,$host,$port = '3306')
{
return $GLOBALS['dbh'] = $database->_connectionID;
}
...
?>

All programs use statement
include_once("$srcdir/sql.inc");
to call function.

Help will be very much appreciated.

A(Answer):

You’re declaring the function twice; you can’t do that.

A(Answer):

Thank you Marcus for reply.
But I declared function only once.
I did search for "function sqlConnect" and got only one file: sql.inc.
No other declaration for this function.
Willlen

A(Answer):

I’m no psychic, so post the rest of the code from sql.inc

You shouldn’t use the .inc extension in case your server doesn’t understand it and prints it as text.

A(Answer):

Programs are big. I post part of the code:
sql.inc

<?php
include_once(dirname(__FILE__) . "/sqlconf.php");
require_once(dirname(__FILE__) . "/adodb/adodb.inc.php");
if (!defined('ADODB_FETCH_ASSOC')) define('ADODB_FETCH_ASSOC', 2);
$database = NewADOConnection("mysql");
$database->PConnect($host, $login, $pass, $dbase);
$GLOBALS['adodb']['db'] = $database;
$GLOBALS['dbh'] = $database->_connectionID;
//fmg: This makes the login screen informative when no connection can be made
if (!$GLOBALS['dbh']) {
//try to be more helpful
if ($host == "localhost") {
echo "Check that mysqld is running.<p>";
} else {
echo "Check that you can ping the server '$host'.<p>";
}//if local
HelpfulDie("Could not connect to server!", mysql_error($GLOBALS['dbh']));
exit;
}//if no connection
function sqlConnect($login,$pass,$dbase,$host,$port = '3306')
{
return $GLOBALS['dbh'] = $database->_connectionID;
}
function sqlStatement($statement)
{
//----------run a mysql query, return the handle
$query = mysql_query($statement, $GLOBALS['dbh']) or
HelpfulDie("query failed: $statement", mysql_error($GLOBALS['dbh']));
return $query;
}
function idSqlStatement($statement)
{
return sqlInsert($statement);
}
function sqlClose()
{
//----------Close our mysql connection
$closed = mysql_close($GLOBALS['dbh']) or
HelpfulDie("could not disconnect from mysql server link", mysql_error($GLOBALS['dbh']));
return $closed;
}
function sqlInsert($statement)
{
//----------run a mysql insert, return the last id generated
mysql_query($statement, $GLOBALS['dbh']) or
HelpfulDie("insert failed: $statement", mysql_error($GLOBALS['dbh']));
return mysql_insert_id($GLOBALS['dbh']);
}
function sqlInsertClean($statement)
{
return sqlInsert($statement);
}
Further are many other functions like above...
?>
Incuding program is login.php:
<?php
$ignoreAuth=true;
include_once("../globals.php");
include_once("$srcdir/md5.js");
include_once("$srcdir/sql.inc");
?>
<html>
<head>
<?php html_header_show(); ?>
<link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
<script language='JavaScript'>
function imsubmitted() {
<?php if (!empty($GLOBALS['restore_sessions'])) { ?>
// Delete the session cookie by setting its expiration date in the past.
// This forces the server to create a new session ID.
var olddate = new Date();
olddate.setFullYear(olddate.getFullYear() - 1);
document.cookie = '<?php echo session_name() . '=' . session_id() ?>; path=/; expires=' + olddate.toGMTString();
<?php } ?>
return true;
}
</script>
</head>
<body <?php echo $login_body_line;?> onload="javascript:document.login_form.authUser.focus();" >
<span class="text"></span>
<center>
<form method="POST" action="../main/main_screen.php?auth=login" target="_top"
name="login_form" onsubmit="return imsubmitted();">
<?php
$res = sqlStatement("select distinct name from groups");
for ($iter = 0;$row = sqlFetchArray($res);$iter++)
$result[$iter] = $row;
if (count($result) == 1) {
$resvalue = $result[0]{"name"};
echo "<input type='hidden' name='authProvider' value='$resvalue' />\n";
}
?>

Further is going a code for entering and transfer login and password …

A(Answer):

It may sound silly but when you search for another instance of your method is case sensitive turned on? Or try a less exclusive search such as "sqlconnect" (note the all lower) while you will get more results than you think that you want you may just find your problem.

Just thinking out loud since the only way you should be receiving this error is if you declare this function twice. Since PHP is a non case sensitive language another function that is capitalized differently may be causing this issue.

A(Answer):

Hi.

On line 72 of your "sql.inc" file you include a file called "sql.inc"
Is this the same file?

If so, then this would cause the error you are seeing.

LEAVE A COMMENT