Fatal Error Cannot Redeclare Class Db Connection
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about
Cannot Redeclare Class Php Error
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask fatal error cannot redeclare class codeigniter Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Php Fatal Error Cannot Redeclare Class Laravel
Join them; it only takes a minute: Sign up PHP: cannot redeclare class up vote 0 down vote favorite 2 So I have 3 classes in this situation. Connection.php Engineer.php Status.php Both Engineer and Status classes actually use connection. php cannot redeclare class require_once Hasn't been a problem but now that I'm using both classes in a page I'm getting Fatal error: Cannot redeclare class Connection Is there a way round this? In both classes I need db access from the connection class. Thanks, Jonesy php class share|improve this question asked Sep 22 '10 at 13:51 iamjonesy 7,72530108184 add a comment| 6 Answers 6 active oldest votes up vote 12 down vote accepted instead of using include() use require_once() for importing Connection.php cannot redeclare class wordpress into Engineer.php and Status.php. share|improve this answer answered Sep 22 '10 at 13:54 burkestar 6701411 thansk! it works! –iamjonesy Sep 22 '10 at 14:12 add a comment| up vote 3 down vote You can always: if( !class_exists('Connection') ) { include('Connection.php'); } or just use include_once(link) or require_once (link) or autoload mechanism share|improve this answer answered Sep 22 '10 at 13:55 petsagouris 7031712 add a comment| up vote 2 down vote Use require_once() rather than require(). Or alternatively, use autoload, which saves you having to specify it loads of times. I suspect the autoload functionality would be the best thing for you, assuming you're using a new-enough version of PHP (it requires 5.3). share|improve this answer answered Sep 22 '10 at 13:56 Spudley 117k28159241 add a comment| up vote 1 down vote Use require_once. share|improve this answer answered Sep 22 '10 at 13:54 Alex Howansky 23.3k24365 add a comment| up vote 1 down vote You are probably using an unsafe class file inclusion method, such as require or include. Try using include_once or require_once. share|improve this answer answered Sep 22 '10 at 13:54 Jacob Relkin 114k23277286 add a comment| up vote 1 down vote well, how are you including the Connection.php? try using require_once. share|improve this answer answered Sep 22 '10 at 13:54 nothrow 10.3k42979 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign u
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Cannot Redeclare Class Database Php
Overflow the company Business Learn more about hiring developers or posting ads with us cannot redeclare class magento 2 Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Php Undeclare Class
community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Fatal error: Cannot redeclare class Database. How to fix? up vote 0 down vote favorite I've http://stackoverflow.com/questions/3769909/php-cannot-redeclare-class seen the question asked but the answer wasn't very clear to me. My code is. index.php login($username, $password); } ?> class.users.php mysqli->prepare("SELECT username, password FROM users WHERE username = ? AND password = ? LIMIT 1"); $stmt->bind_param('ss', $username, $password); $stmt->execute(); $stmt->bind_result($username, http://stackoverflow.com/questions/25633390/fatal-error-cannot-redeclare-class-database-how-to-fix $password); $stmt->store_result(); if($stmt->num_rows == 1) { while($stmt->fetch()) { $_SESSION['username'] == $username; header("Location: dashboard.php"); } } else { return false; } $stmt->close(); $stmt->free_result(); } } $users = new users(); ?> connect.php mysqli = new mysqli($host, $user, $pass, $name); } } ?> The class Database isn't called twice? so how is it a error? can anyone explain why in the comments. php mysql share|improve this question edited Sep 2 '14 at 22:33 asked Sep 2 '14 at 22:28 logchipperman 12 what's in connect.php? –Sam D Sep 2 '14 at 22:32 I wonder if class Database is already declared or included in header.php or connect.php? –Bill Karwin Sep 2 '14 at 22:32 sorry i forgot the add in connect.php –logchipperman Sep 2 '14 at 22:33 yeah its included with header.php is that the problem?? –logchipperman Sep 2 '14 at 22:36 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote you could test to see if its already declared before doing so: if (!isset($database) && !is_a($database, 'Database')){ $database = new Database(); } Or if you're declaring it inside connect.php you could: include
this is your first visit, be sure http://www.webdeveloper.com/forum/showthread.php?249186-Fatal-error-Cannot-redeclare-class-DBConnect to check out the FAQ by clicking the http://forums.devnetwork.net/viewtopic.php?f=1&t=105344 link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection cannot redeclare below. Results 1 to 3 of 3 Thread: Fatal error: Cannot redeclare class DBConnect Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 07-24-2011,02:39 AM #1 soda cannot redeclare class View Profile View Forum Posts Registered User Join Date May 2008 Posts 53 Fatal error: Cannot redeclare class DBConnect I have 3 pages. 1.ledger.php 2.ledgerDAO.php (ledger class ) 3.authenticate.php (login class) 1. ledger.php PHP Code: index All times are UTC - 5 hours Information The requested topic does not exist. Board index All times are UTC - 5 hours Powered by phpBB Forum Software © phpBB Group
[COLOR="Red"]require("Classes/ledger/LedgerDAO.php");
require("Classes/login/authenticate.php");[/COLOR]
$authenticate_users=newauthenticate_users();
$authenticate_users->confirm_member();
if(@$_GET['q']=='logout'){
$authenticate_users->log_out();
header(