error in class
bertlim - 16/03/2006 18:12
PHP interesse
Hoi iedereen,
ik ben pas begonnen met classes en ik heb nu een mysqlclass gemaakt.
Maar nu krijg ik deze error:
Fatal error: Cannot redeclare class mysqldatabase in /www/users/bertlim.downfire.com/classes/SQLclass.php on line 11
dit is men code:
<?php
class MySqlDatabase
{
var $host = '';
var $user = '';
var $pass = '';
var $data = '';
var $connected = false;
var $connectie;
var $countquerys = 0;
var $querytime;
var $execed;
function cError($title,$error)
{
echo '<font face="verdana" size="12" color="#FF0033"> '.$title.' </font><p>';
echo '<font face="Verdana" size="10" color="#FF0000"> '.$error.' </font>';
}
function cConnect($host, $user, $pass, $data)
{
if($this->connected = false)
{
$this->connectie = mysql_connect($host,$user,$pass);
}
elseif($this->connected = true && isset($this->connectie))
{
return $this->connectie;
}
elseif(!mysql_connect($data))
{
die($this->cError('Database Error ::','The database can not be found. Try again later.'));
}
else
{
$this->connected = true;
}
}
function cMicrotime()
{
$time = explode(' ', microtime());
return $time[0] + $time[1];
}
function cQuerys($input)
{
$start_time = $this->cMicrotime();
$query = mysql_query($input) or die($this->error('Query Error ::', 'An error occured while processing the query.'));
$this->execed = 1;
$this->countquerys++;
$time = $this->cMicrotime() - $start_time;
$this->querytime += $time;
return $query;
}
function cFetch($input)
{
if($this->execed != 1)
{
die($this->cError('Query Error ::', 'No query processed.'));
}
return mysql_fetch_assoc($input);
}
function cNumRows($input)
{
if($this->execed != 1)
{
die($this->cError('Query Error ::', 'No query processed.'));
}
return mysql_num_rows($input);
}
function cQueryOutput()
{
if($this->countquerys == 1)
{
echo '<font face="verdana" size="8">1 query executed.</font>';
$query_name = 'query';
}
else
{
echo '<font face="verdana" size="8"> '.$this->countquerys.' query\'s executed.</font>';
$query_name = 'query\'s';
}
echo '<br><font face="verdana" size="8">'.$query_name.' executed in '.round($this->querytime,5).' Ms.</font>';
}
}
?>
<?php
class MySqlDatabase
{
var $host = '' ;
var $user = '' ;
var $pass = '' ;
var $data = '' ;
var $connected = false ;
var $connectie ;
var $countquerys = 0 ;
var $querytime ;
var $execed ;
function cError( $title , $error )
{
echo '<font face="verdana" size="12" color="#FF0033"> ' . $title . ' </font><p>' ; echo '<font face="Verdana" size="10" color="#FF0000"> ' . $error . ' </font>' ; }
function cConnect( $host , $user , $pass , $data )
{
if ( $this -> connected = false )
{
}
elseif ( $this -> connected = true && isset ( $this -> connectie ) ) {
return $this -> connectie ;
}
{
die ( $this -> cError ( 'Database Error ::' , 'The database can not be found. Try again later.' ) ) ; }
else
{
$this -> connected = true ;
}
}
function cMicrotime( )
{
return $time [ 0 ] + $time [ 1 ] ;
}
function cQuerys( $input )
{
$start_time = $this -> cMicrotime ( ) ;
$query = mysql_query ( $input ) or
die ( $this -> error ( 'Query Error ::' , 'An error occured while processing the query.' ) ) ; $this -> execed = 1 ;
$this -> countquerys ++;
$time = $this -> cMicrotime ( ) - $start_time ;
$this -> querytime += $time ;
return $query ;
}
function cFetch( $input )
{
if ( $this -> execed != 1 )
{
die ( $this -> cError ( 'Query Error ::' , 'No query processed.' ) ) ; }
}
function cNumRows( $input )
{
if ( $this -> execed != 1 )
{
die ( $this -> cError ( 'Query Error ::' , 'No query processed.' ) ) ; }
}
function cQueryOutput( )
{
if ( $this -> countquerys == 1 )
{
echo '<font face="verdana" size="8">1 query executed.</font>' ; $query_name = 'query' ;
}
else
{
echo '<font face="verdana" size="8"> ' . $this -> countquerys . ' query\' s executed
.</ font
> '; $query_name = ' query\'s' ;
}
echo '<br><font face="verdana" size="8">' . $query_name . ' executed in ' . round ( $this -> querytime , 5 ) . ' Ms.</font>' ; }
}
?>
Kan iemand me helpen?
bedankt bij voorbaat,
Bertlim
9 antwoorden
Gesponsorde links
vinTage - 16/03/2006 18:47 (laatste wijziging 16/03/2006 18:47)
Nieuw lid
Fatal error: Cannot redeclare class mysqldatabase in /www/users/bertlim.downfire.com/classes/SQLclass.php on line 11
Je kan class maar één keer aanroepen, dus wss roep je elders die class nog eens aan (in een include mss? )
bertlim - 16/03/2006 20:58 (laatste wijziging 16/03/2006 21:02)
PHP interesse
ok dit probleem is nu opgelost maar nu krijg ik deze errors:
Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /www/users/bertlim.downfire.com/classes/SQLclass.php on line 39
Warning: mysql_select_db(): A link to the server could not be established in /www/users/bertlim.downfire.com/classes/SQLclass.php on line 39
Code:
<?php
class MySqlDatabase
{
var $host = '';
var $user = '';
var $pass = '';
var $data = '';
var $connected = false;
var $connectie;
var $countquerys = 0;
var $querytime;
var $execed;
function cError($title,$error)
{
echo '<font face="verdana" size="12" color="#FF0033"> '.$title.' </font><p>';
echo '<font face="Verdana" size="10" color="#FF0000"> '.$error.' </font>';
}
function cConnect($host, $user, $pass, $data)
{
if($this->connected = false)
{
$this->connectie = mysql_connect($host,$user,$pass);
}
elseif($this->connected = true && isset($this->connectie))
{
return $this->connectie;
}
elseif(!mysql_select_db($data))
{
die($this->cError('Database Error ::','The database can not be found. Try again later.'));
}
else
{
$this->connected = true;
}
}
function cMicrotime()
{
$time = explode(' ', microtime());
return $time[0] + $time[1];
}
function cQuerys($input)
{
$start_time = $this->cMicrotime();
$query = mysql_query($input) or die($this->error('Query Error ::', 'An error occured while processing the query.'));
$this->execed = 1;
$this->countquerys++;
$time = $this->cMicrotime() - $start_time;
$this->querytime += $time;
return $query;
}
function cFetch($input)
{
if($this->execed != 1)
{
die($this->cError('Query Error ::', 'No query processed.'));
}
return mysql_fetch_assoc($input);
}
function cNumRows($input)
{
if($this->execed != 1)
{
die($this->cError('Query Error ::', 'No query processed.'));
}
return mysql_num_rows($input);
}
function cQueryOutput()
{
if($this->countquerys == 1)
{
echo '<font face="verdana" size="8">1 query executed.</font>';
$query_name = 'query';
}
else
{
echo '<font face="verdana" size="8"> '.$this->countquerys.' query\'s executed.</font>';
$query_name = 'query\'s';
}
echo '<br><font face="verdana" size="8">'.$query_name.' executed in '.round($this->querytime,5).' Ms.</font>';
}
}
?>
<?php
class MySqlDatabase
{
var $host = '' ;
var $user = '' ;
var $pass = '' ;
var $data = '' ;
var $connected = false ;
var $connectie ;
var $countquerys = 0 ;
var $querytime ;
var $execed ;
function cError( $title , $error )
{
echo '<font face="verdana" size="12" color="#FF0033"> ' . $title . ' </font><p>' ; echo '<font face="Verdana" size="10" color="#FF0000"> ' . $error . ' </font>' ; }
function cConnect( $host , $user , $pass , $data )
{
if ( $this -> connected = false )
{
}
elseif ( $this -> connected = true && isset ( $this -> connectie ) ) {
return $this -> connectie ;
}
{
die ( $this -> cError ( 'Database Error ::' , 'The database can not be found. Try again later.' ) ) ; }
else
{
$this -> connected = true ;
}
}
function cMicrotime( )
{
return $time [ 0 ] + $time [ 1 ] ;
}
function cQuerys( $input )
{
$start_time = $this -> cMicrotime ( ) ;
$query = mysql_query ( $input ) or
die ( $this -> error ( 'Query Error ::' , 'An error occured while processing the query.' ) ) ; $this -> execed = 1 ;
$this -> countquerys ++;
$time = $this -> cMicrotime ( ) - $start_time ;
$this -> querytime += $time ;
return $query ;
}
function cFetch( $input )
{
if ( $this -> execed != 1 )
{
die ( $this -> cError ( 'Query Error ::' , 'No query processed.' ) ) ; }
}
function cNumRows( $input )
{
if ( $this -> execed != 1 )
{
die ( $this -> cError ( 'Query Error ::' , 'No query processed.' ) ) ; }
}
function cQueryOutput( )
{
if ( $this -> countquerys == 1 )
{
echo '<font face="verdana" size="8">1 query executed.</font>' ; $query_name = 'query' ;
}
else
{
echo '<font face="verdana" size="8"> ' . $this -> countquerys . ' query\' s executed
.</ font
> '; $query_name = ' query\'s' ;
}
echo '<br><font face="verdana" size="8">' . $query_name . ' executed in ' . round ( $this -> querytime , 5 ) . ' Ms.</font>' ; }
}
?>
kan iemand me helpen?
Bedankt bij voorbaat,
Bertlim
ikkedikke - 17/03/2006 16:30
PHP expert
heb je voor host wel iets ingevuld? zo nee: dan moet je bij je host te raden gaan, zo ja: wat dan?
MothZone - 17/03/2006 16:34
PHP ver gevorderde
Regels (volgens script hierboven) 23 tot 27:
if($this->connected = false)
{
$this->connectie = mysql_connect($host,$user,$pass);
}
elseif($this->connected = true && isset($this->connectie))
if ( $this -> connected = false )
{
}
elseif ( $this -> connected = true && isset ( $this -> connectie ) )
Moet dit zijn:
if($this->connected == false)
{
$this->connectie = mysql_connect($host,$user,$pass);
}
elseif($this->connected == true && isset($this->connectie))
if ( $this -> connected == false )
{
}
elseif ( $this -> connected == true && isset ( $this -> connectie ) )
Als je if($a = $b) doet, dan krijgt $a de waarde van $b, en geeft hij automatisch true, als je if($a == $b) doet, geeft hij alleen true als ze aan elkaar gelijk zijn.
bertlim - 17/03/2006 17:10
PHP interesse
ok hij werkt nu.
bedankt allemaal!
timo - 17/03/2006 17:14
PHP ver gevorderde
als je false of true wil weten is het === d8 k..
bertlim - 17/03/2006 22:43
PHP interesse
nu heb ik een ander probleem met een andere class.
Ik krijg bij het inloggen mooi het inlog venstertje te zien en als ik inlog krijg ik deze error:
Fatal error: Call to a member function on a non-object in /www/users/bertlim.downfire.com/classes/Memberclass.php on line 137
dit is men code:
<?
class MemberClass
{
function cError($title,$error)
{
echo '<font face="verdana" size="12" color="#FF0033"> '.$title.' </font><p>';
echo '<font face="Verdana" size="10" color="#FF0000"> '.$error.' </font>';
}
function cSuperAdmin()
{
if(!empty($_SESSION['user']) && !empty($_SESSION['pass']))
{
$MyQu[0] = $db->cQuerys("SELECT * FROM members WHERE username = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."'");
if($db->cNumRows($MyQu[0]) != 1)
{
die($this->cErrors('User Error ::','The user can not be found, or your login data is wrong.'));
}
$MyAs[0] = $db->cFetch($MyQu[0]);
if($_SESSION['user'] == $MyAs[0]['username'] && $_SESSION['pass'] == $MyAs[0]['pass'] && $MyAs[0]['level'] == '4')
{
return true;
}
else
{
return false;
}
}
}
function cAdmin()
{
if(!empty($_SESSION['user']) && !empty($_SESSION['pass']))
{
$MyQu[1] = $db->cQuerys("SELECT * FROM members WHERE username = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."'");
if($db->cNumRows($MyQu[1]) != 1)
{
die($this->cErrors('User Error ::','The user can not be found, or your login data is wrong.'));
}
$MyAs[1] = $db->cFetch($MyQu[1]);
if($_SESSION['user'] == $MyAs[1]['username'] && $_SESSION['pass'] == $MyAs[1]['pass'] && $MyAs[1]['level'] == '3')
{
return true;
}
else
{
return false;
}
}
}
function cModerator()
{
if(!empty($_SESSION['user']) && !empty($_SESSION['pass']))
{
$MyQu[2] = $db->cQuerys("SELECT * FROM members WHERE username = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."'");
if($db->cNumRows($MyQu[2]) != 1)
{
die($this->cErrors('User Error ::','The user can not be found, or your login data is wrong.'));
}
$MyAs[2] = $db->cFetch($MyQu[2]);
if($_SESSION['user'] == $MyAs[2]['username'] && $_SESSION['pass'] == $MyAs[2]['pass'] && $MyAs[2]['level'] == '2')
{
return true;
}
else
{
return false;
}
}
}
function cMember()
{
if(!empty($_SESSION['user']) && !empty($_SESSION['pass']))
{
$MyQu[3] = $db->cQuerys("SELECT * FROM members WHERE username = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."'");
if($db->cNumRows($MyQu[3]) != 1)
{
die($this->cErrors('User Error ::','The user can not be found, or your login data is wrong.'));
}
$MyAs[3] = $db->cFetch($MyQu[3]);
if($_SESSION['user'] == $MyAs[3]['username'] && $_SESSION['pass'] == $MyAs[3]['pass'] && $MyAs[3]['level'] == '1')
{
return true;
}
else
{
return false;
}
}
}
function cRegister($username,$pass,$pass_confirm,$email)
{
if(!empty($username) && !empty($pass) && !empty($pass_confirm)&& !empty($email))
{
if($pass == $pass_confirm)
{
$MyQu[4] = $db->cQuerys("SELECT * FROM members WHERE username = '".$username."'");
$MyNu[0] = $db->cNumRows($MyQu[4]);
if($MyNu[0] != 1)
{
$db->cQuerys("INSERT INTO members username, pass, email, level VALUES ('".$username."','".$pass."','".$email."','1')");
echo 'Registration Complete.<a href="login.php">login</a>.';
}
else
{
$this->cErrors('User Error ::','The username already exists.Choose another one.');
}
}
else
{
$this->cErrors('Password Error ::','Your passwords do not match.');
}
}
else
{
$this->cErrors('Input Error ::','You need to fill in all fields.');
}
}
function cLogin($username,$pass)
{
if(!empty($username) && !empty($pass))
{
$MyQu[5] = $db->cQuerys("SELECT * FROM members WHERE username = '".$username."' AND pass = '".$pass."'");
$MyNu[1] = $db->cNumRows($MyQu[5]);
if($MyNu[1] != 0)
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
echo 'Login Succesfull. <a href="index.php">Go to index</a>.';
}
else
{
$this->cErrors('User Error ::','This User does not exist or your login data is wrong.');
}
}
else
{
$this->cErrors('Input Error ::','You need to fill in all fields.');
}
}
function MembersList()
{
$MyQu[6] = $db->cQuerys("SELECT * FROM members ORDER BY id DESC");
$MyNu[2] = $db->cNumRows($MyQu[6]);
if($MyNu[2] == 0)
{
echo 'No members registered yet.';
}
while($MyAs[4] = $db->cFetch($MyQu[6]))
{
echo '<table>
<tr>
<td width="200">Name</td>
<td width="200">Email</td>
<td width="200">Status</td>
</tr>
<tr>
<td width="200">'.$MyAs[4]['username'].'</td>
<td width="200">'.$MyAs[4]['email'].'</td>
<td width="200">'.$status.'</td>';
}
}
}
?>
<?
class MemberClass
{
function cError( $title , $error )
{
echo '<font face="verdana" size="12" color="#FF0033"> ' . $title . ' </font><p>' ; echo '<font face="Verdana" size="10" color="#FF0000"> ' . $error . ' </font>' ; }
function cSuperAdmin( )
{
if ( ! empty ( $_SESSION [ 'user' ] ) && ! empty ( $_SESSION [ 'pass' ] ) ) {
$MyQu [ 0 ] = $db -> cQuerys ( "SELECT * FROM members WHERE username = '" . $_SESSION [ 'user' ] . "' AND pass = '" . $_SESSION [ 'pass' ] . "'" ) ;
if ( $db -> cNumRows ( $MyQu [ 0 ] ) != 1 )
{
die ( $this -> cErrors ( 'User Error ::' , 'The user can not be found, or your login data is wrong.' ) ) ; }
$MyAs [ 0 ] = $db -> cFetch ( $MyQu [ 0 ] ) ;
if ( $_SESSION [ 'user' ] == $MyAs [ 0 ] [ 'username' ] && $_SESSION [ 'pass' ] == $MyAs [ 0 ] [ 'pass' ] && $MyAs [ 0 ] [ 'level' ] == '4' )
{
return true ;
}
else
{
return false ;
}
}
}
function cAdmin( )
{
if ( ! empty ( $_SESSION [ 'user' ] ) && ! empty ( $_SESSION [ 'pass' ] ) ) {
$MyQu [ 1 ] = $db -> cQuerys ( "SELECT * FROM members WHERE username = '" . $_SESSION [ 'user' ] . "' AND pass = '" . $_SESSION [ 'pass' ] . "'" ) ;
if ( $db -> cNumRows ( $MyQu [ 1 ] ) != 1 )
{
die ( $this -> cErrors ( 'User Error ::' , 'The user can not be found, or your login data is wrong.' ) ) ; }
$MyAs [ 1 ] = $db -> cFetch ( $MyQu [ 1 ] ) ;
if ( $_SESSION [ 'user' ] == $MyAs [ 1 ] [ 'username' ] && $_SESSION [ 'pass' ] == $MyAs [ 1 ] [ 'pass' ] && $MyAs [ 1 ] [ 'level' ] == '3' )
{
return true ;
}
else
{
return false ;
}
}
}
function cModerator( )
{
if ( ! empty ( $_SESSION [ 'user' ] ) && ! empty ( $_SESSION [ 'pass' ] ) ) {
$MyQu [ 2 ] = $db -> cQuerys ( "SELECT * FROM members WHERE username = '" . $_SESSION [ 'user' ] . "' AND pass = '" . $_SESSION [ 'pass' ] . "'" ) ;
if ( $db -> cNumRows ( $MyQu [ 2 ] ) != 1 )
{
die ( $this -> cErrors ( 'User Error ::' , 'The user can not be found, or your login data is wrong.' ) ) ; }
$MyAs [ 2 ] = $db -> cFetch ( $MyQu [ 2 ] ) ;
if ( $_SESSION [ 'user' ] == $MyAs [ 2 ] [ 'username' ] && $_SESSION [ 'pass' ] == $MyAs [ 2 ] [ 'pass' ] && $MyAs [ 2 ] [ 'level' ] == '2' )
{
return true ;
}
else
{
return false ;
}
}
}
function cMember( )
{
if ( ! empty ( $_SESSION [ 'user' ] ) && ! empty ( $_SESSION [ 'pass' ] ) ) {
$MyQu [ 3 ] = $db -> cQuerys ( "SELECT * FROM members WHERE username = '" . $_SESSION [ 'user' ] . "' AND pass = '" . $_SESSION [ 'pass' ] . "'" ) ;
if ( $db -> cNumRows ( $MyQu [ 3 ] ) != 1 )
{
die ( $this -> cErrors ( 'User Error ::' , 'The user can not be found, or your login data is wrong.' ) ) ; }
$MyAs [ 3 ] = $db -> cFetch ( $MyQu [ 3 ] ) ;
if ( $_SESSION [ 'user' ] == $MyAs [ 3 ] [ 'username' ] && $_SESSION [ 'pass' ] == $MyAs [ 3 ] [ 'pass' ] && $MyAs [ 3 ] [ 'level' ] == '1' )
{
return true ;
}
else
{
return false ;
}
}
}
function cRegister( $username , $pass , $pass_confirm , $email )
{
{
if ( $pass == $pass_confirm )
{
$MyQu [ 4 ] = $db -> cQuerys ( "SELECT * FROM members WHERE username = '" . $username . "'" ) ;
$MyNu [ 0 ] = $db -> cNumRows ( $MyQu [ 4 ] ) ;
if ( $MyNu [ 0 ] != 1 )
{
$db -> cQuerys ( "INSERT INTO members username, pass, email, level VALUES ('" . $username . "','" . $pass . "','" . $email . "','1')" ) ;
echo 'Registration Complete.<a href="login.php">login</a>.' ; }
else
{
$this -> cErrors ( 'User Error ::' , 'The username already exists.Choose another one.' ) ;
}
}
else
{
$this -> cErrors ( 'Password Error ::' , 'Your passwords do not match.' ) ;
}
}
else
{
$this -> cErrors ( 'Input Error ::' , 'You need to fill in all fields.' ) ;
}
}
function cLogin( $username , $pass )
{
{
$MyQu [ 5 ] = $db -> cQuerys ( "SELECT * FROM members WHERE username = '" . $username . "' AND pass = '" . $pass . "'" ) ;
$MyNu [ 1 ] = $db -> cNumRows ( $MyQu [ 5 ] ) ;
if ( $MyNu [ 1 ] != 0 )
{
$_SESSION [ 'user' ] = $user ;
$_SESSION [ 'pass' ] = $pass ;
echo 'Login Succesfull. <a href="index.php">Go to index</a>.' ; }
else
{
$this -> cErrors ( 'User Error ::' , 'This User does not exist or your login data is wrong.' ) ;
}
}
else
{
$this -> cErrors ( 'Input Error ::' , 'You need to fill in all fields.' ) ;
}
}
function MembersList( )
{
$MyQu [ 6 ] = $db -> cQuerys ( "SELECT * FROM members ORDER BY id DESC" ) ;
$MyNu [ 2 ] = $db -> cNumRows ( $MyQu [ 6 ] ) ;
if ( $MyNu [ 2 ] == 0 )
{
echo 'No members registered yet.' ; }
while ( $MyAs [ 4 ] = $db -> cFetch ( $MyQu [ 6 ] ) )
{
<tr>
<td width="200">Name</td>
<td width="200">Email</td>
<td width="200">Status</td>
</tr>
<tr>
<td width="200">' . $MyAs [ 4 ] [ 'username' ] . '</td>
<td width="200">' . $MyAs [ 4 ] [ 'email' ] . '</td>
<td width="200">' . $status . '</td>' ;
}
}
}
?>
kan iemand me helpen?
bedankt bij voorbaat,
Bertlim
Gesponsorde links
Dit onderwerp is gesloten .