Darksat IT Security Forums
December 13, 2017, 05:04:10 am
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Darksat IT Security Forum
From Firewall Support, AntiVirus Questions, Spyware problems, Linux and Windows Security, Black Hat SEO right down to Website Design and Multimedia
 
  Home Help Search Gallery Links Staff List Login Register  

Cannot redeclare class


Pages: [1]
  Print  
Author Topic: Cannot redeclare class  (Read 2113 times)
Defcon 5
Master
*****
Posts: 2410



View Profile WWW
« on: December 17, 2008, 02:20:31 pm »

Quote
Fatal error: Cannot redeclare class DB in C:\***\htdocs\smile\admin\function.php on line 5


so this is functions line 5 is class DB{
Code:
<?php 

require('vars.php');

class 
DB{

function query($query){
mysql_connect($mysqllocation,$mysqlusername,$mysqlpassword) or die('Connection Failed');
mysql_select_db($mysqldatabase) or die("Unable to select database");
mysql_query($query) or die('Query Error');
mysql_close();
}

function row($query){
$connect mysql_connect($mysqllocation,$mysqlusername,$mysqlpassword);
mysql_select_db($mysqldatabase$connect);
$result mysql_query($query) or die(mysql_error());
$row mysql_fetch_array($result) or die(mysql_error());
return $row;
}
}


?>

I tried include_once vars in the functions itself and include vars in the function...

Now I've seen people using public vars... I don't get by the way... so am I calling my vars wrong because their just strings containing mysql data?


From what I understand using require halts the script causing a fatal error?
But when I comment it out I still get a fatal error.
« Last Edit: December 17, 2008, 02:42:45 pm by Defcon 5 » Report Spam   Logged

Social Buttons

Darksat
Administrator
Master
*******
Posts: 3303



View Profile WWW
« Reply #1 on: December 19, 2008, 07:47:07 am »

Actually I generally use include not requre, esentially they are the same but require will cause a fatal error that will stop the script where as include will run the rest of the script even if the include is missing.
So if you switch to include you normally get a more detailed error message.
so try include_once as this prevents the functions getting declared multiple time. (and switch to requre_once when it goes live for security reasons)
Report Spam   Logged
Defcon 5
Master
*****
Posts: 2410



View Profile WWW
« Reply #2 on: December 19, 2008, 01:18:05 pm »

Cheers, fixed Grin.

Next question... so my DB functions, are they a good way to use them... because I've seen another method where you run say DB::query() to then be able to use DB::row() is their a advantage in that?

From what I take it query is opening the connection, but then how can you intigrate that with my fetching a row?
Report Spam   Logged
Darksat
Administrator
Master
*******
Posts: 3303



View Profile WWW
« Reply #3 on: December 27, 2008, 10:10:07 am »

Its a case of deep tree structure versus flat structure.
DB Query is handy if you have loads of queries to the database on multiple pages and multiple times, however if its a simple script/site with only a couple of connections then its not needed and you better going with the simple option.
Report Spam   Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
eXTReMe Tracker
Security Forum
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Buy traffic for your forum/website
traffic-masters
Powered by SMF | SMF © 2016, Simple Machines
Page created in 0.109 seconds with 10 queries.