0

hello people

i am new to oop , well , i am good in the normal php but i started oop today and now i am getting too many errors . check the class_lib.php bellow , it has my classes and mainly the database connectors .:

<?php
class db
{
var $do;
function __construct()
{
mysql_connect("localhost","root")or die("cant connect to MySQL server : ".mysql_error());
}
function select($select)
{
mysql_select_db($select) or die("cant select the db : ".$select);
}
function query($data)
{
$q = mysql_query($data);
if($q)
{
echo "";
}
else
{
echo "Error : ".mysql_error();
}
}
function close()
{
mysql_close();
}
}
?>

so when ever i want to connect to the database i use such code

<?php
$db = new db();
$db->select("database name");
$db->query("SELECT * FROM tbl_name");

and i get what i want but , when i wanted to do many connections in my website's sidebare i get this error :

Fatal error: Cannot redeclare class db in C:\xampp\htdocs\awah.biz2\classes\class_lib.php on line 3

here is the code of the side bar :

<div id="sidebar">
			<ul>
				<li>
                <div id="sn">
                <A href="http://facebook.com/awah.mohamad" title="Add us on facebook"><img src="images/facebook-icon.png" alt="Awah Dot Biz" width="80px" height="80px" /></A> &nbsp; &nbsp;
                <a href="http://twitter.com/awahQI" accesskey="t" title="Follow Awah Dot Biz on twitter"><img src="images/twitter.png" alt="Follow Awah Dot Biz on twitter" alt="Awah Dot Biz" width="80px" height="80px" /></a>
					<div id="search" >
					<form method="get" action="search.php">
						<div>
							<input type="text" name="q" id="search-text" value="" />
							<input type="submit" id="search-submit" value="GO" />
						</div>
					</form>
					</div>
					<div style="clear: both;">&nbsp;</div>
				</li>
				<li>
					<h2>News</h2>
                    <p>
					<?php
                    include "classes/class_lib.php";
					$dt = new db();
					$dt->select("awah7870_index");
					$q = "SELECT * FROM news ORDER BY id DESC limit 0,5";
					$n = 1;
					while($rows = $dt->query($q))
					{
					echo "<strong>".$n."/".$rows['title']."</strong><BR>";
					echo "<BR>".$rows['news']."<BR>";
					$n++;
					}
					?>
                    			
					
					
					</p>
				</li>
				<li>
					<h2>Categories</h2>
					<ul>
                    <?php
					$dd = new db();
					$query = "SELECT * FROM sections";
					while($rows = $dd->query($query))
					{
					?>
						<li><a href="sections.php?s_id=<?php echo $rows['id']; ?>" title="<?php echo $rows['des']; ?>" ><?php echo $rows['name']; ?></a></li>
                        <?php
						}
						?>
						
					</ul>
                    
				</li>
                <li>
                     <h2 title="Awah dot biz pages">pages</h2>
                     <ul>
                     <?php
					 $ddd = new db();
					 $query = "SELECT * FROM pages";
					 while($rows = $ddd->query($query))
					 {
					 ?>
                     <li><a href="pages.php?p_id=<?php echo $rows['id']; ?>" title="<?php echo $rows['des']; ?>"><?php echo $rows['title']; ?></a></li>
                     <?php
					 }
					 ?>
                     </ul>
                     </li>
                     <li>
                     <h2 title="awah dot biz links">Sugested links</h2>
                     <ul>
                     <?php
					 $dbd = new db();
					 $qq = "SELECT * FROM links";
					while($rows = $dbd->query($qq))
					{
					?>
                     <li title="<?php echo $rows['title']; ?>"><A href="<?php echo $rows['link']; ?>"><?php echo $rows['name']; ?></A></li>
                     <?php
					 }
					 ?>
                     </ul>
				</li>
              
			</ul>
		</div>

well i tried to solve it alone by creating new db() each time i have a sql connection , but bnothing was gained .

please tell me what am i supposed to do ....
thanks .

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by P0lT10n
0

your problem is that you cant reconect when you connected to mysql... you have first to close conection...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.