By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Cannot redeclare foo() error

P: 5
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ...
  3. function sqlConnect($login,$pass,$dbase,$host,$port = '3306')
  4. {
  5.   return $GLOBALS['dbh'] = $database->_connectionID;
  6. }
  7. ...
  8. ?>
All programs use statement
include_once("$srcdir/sql.inc");
to call function.

Help will be very much appreciated.
Oct 17 '08 #1
Share this Question
Share on Google+
6 Replies


Markus
Expert 5K+
P: 6,050
You're declaring the function twice; you can't do that.
Oct 17 '08 #2

P: 5
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
Oct 17 '08 #3

Markus
Expert 5K+
P: 6,050
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.
Oct 17 '08 #4

P: 5
Programs are big. I post part of the code:
sql.inc
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include_once(dirname(__FILE__) . "/sqlconf.php");
  3. require_once(dirname(__FILE__) . "/adodb/adodb.inc.php");
  4.  
  5. if (!defined('ADODB_FETCH_ASSOC')) define('ADODB_FETCH_ASSOC', 2);
  6. $database = NewADOConnection("mysql");
  7. $database->PConnect($host, $login, $pass, $dbase);
  8. $GLOBALS['adodb']['db'] = $database;
  9. $GLOBALS['dbh'] = $database->_connectionID;
  10.  
  11. //fmg: This makes the login screen informative when no connection can be made
  12. if (!$GLOBALS['dbh']) {
  13.   //try to be more helpful
  14.   if ($host == "localhost") {
  15.     echo "Check that mysqld is running.<p>";
  16.   } else {
  17.     echo "Check that you can ping the server '$host'.<p>";
  18.   }//if local
  19.   HelpfulDie("Could not connect to server!", mysql_error($GLOBALS['dbh']));
  20.   exit;
  21. }//if no connection
  22.  
  23. function sqlConnect($login,$pass,$dbase,$host,$port = '3306')
  24. {
  25.   return $GLOBALS['dbh'] = $database->_connectionID;
  26. }
  27.  
  28. function sqlStatement($statement)
  29. {
  30.   //----------run a mysql query, return the handle
  31.   $query = mysql_query($statement, $GLOBALS['dbh']) or 
  32.     HelpfulDie("query failed: $statement", mysql_error($GLOBALS['dbh']));
  33.   return $query;
  34. }
  35.  
  36. function idSqlStatement($statement)
  37. {
  38.   return sqlInsert($statement);
  39. }
  40.  
  41. function sqlClose()
  42. {
  43.   //----------Close our mysql connection
  44.   $closed = mysql_close($GLOBALS['dbh']) or
  45.     HelpfulDie("could not disconnect from mysql server link", mysql_error($GLOBALS['dbh']));
  46.   return $closed;
  47. }
  48.  
  49. function sqlInsert($statement)
  50. {
  51.   //----------run a mysql insert, return the last id generated
  52.   mysql_query($statement, $GLOBALS['dbh']) or 
  53.     HelpfulDie("insert failed: $statement", mysql_error($GLOBALS['dbh']));
  54.   return mysql_insert_id($GLOBALS['dbh']);
  55. }
  56.  
  57. function sqlInsertClean($statement)
  58. {
  59.   return sqlInsert($statement);
  60. }
  61.  
  62. Further are many other functions like above...
  63.  
  64. ?>
  65.  
  66. Incuding program is login.php:
  67. <?php
  68.  
  69. $ignoreAuth=true;
  70. include_once("../globals.php");
  71. include_once("$srcdir/md5.js");
  72. include_once("$srcdir/sql.inc");
  73. ?>
  74.  
  75. <html>
  76. <head>
  77. <?php html_header_show(); ?>
  78. <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
  79.  
  80. <script language='JavaScript'>
  81.  
  82. function imsubmitted() {
  83. <?php if (!empty($GLOBALS['restore_sessions'])) { ?>
  84.  // Delete the session cookie by setting its expiration date in the past.
  85.  // This forces the server to create a new session ID.
  86.  var olddate = new Date();
  87.  olddate.setFullYear(olddate.getFullYear() - 1);
  88.  document.cookie = '<?php echo session_name() . '=' . session_id() ?>; path=/; expires=' + olddate.toGMTString();
  89. <?php  }  ?>
  90.  return true;
  91. }
  92.  
  93. </script>
  94.  
  95. </head>
  96. <body <?php echo $login_body_line;?> onload="javascript:document.login_form.authUser.focus();" >
  97.  
  98. <span class="text"></span>
  99.  
  100. <center>
  101.  
  102. <form method="POST" action="../main/main_screen.php?auth=login" target="_top"
  103.  name="login_form" onsubmit="return imsubmitted();">
  104.  
  105. <?php
  106. $res = sqlStatement("select distinct name from groups");
  107. for ($iter = 0;$row = sqlFetchArray($res);$iter++)
  108.     $result[$iter] = $row;
  109. if (count($result) == 1) {
  110.     $resvalue = $result[0]{"name"};
  111.     echo "<input type='hidden' name='authProvider' value='$resvalue' />\n";
  112. }
  113. ?>
Further is going a code for entering and transfer login and password ...
Oct 17 '08 #5

P: 9
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.
Oct 18 '08 #6

Atli
Expert 5K+
P: 5,058
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.
Oct 18 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.