Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4624734
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:10:15+00:00 2026-05-22T03:10:15+00:00

I have 3 files: DB.class.php – which handles all the databases. Site.class.php – contains

  • 0

I have 3 files:

DB.class.php – which handles all the databases.
Site.class.php – contains a function to return the latest entries in a database.
index.php – trying to print the array passed.

I am trying to pass an array into index.php from Site.class.php which is using a function from DB.class.php to put the mysql results into an associative array.

index.php:

<?php

// index.php

include 'classes/Site.class.php';
$site = new Site();

print_r($site->latestBookmarks());

?>

Site.class.php:

<?php 

// Site.class.php

require_once 'DB.class.php';

class Site {

    function latestBookmarks() {

        $result = mysql_query("SELECT url, title FROM site ORDER BY id DESC");

        $db = new DB();

        return $db->processRowSet($result);

    }

}

?>

DB.class.php:

<?php 

// DB.class.php

class DB {

    protected $db_name = "project";
    protected $db_user = "root";
    protected $db_pass = "root";
    protected $db_host = "localhost";

    // Open up a connection to the database.

    public function connect() {

        $connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
        mysql_select_db($this->db_name);

        return true;

    }

    // Takes a MySQL row and returns an associative array where the keys in the array are the column names in the row set.

    public function processRowSet($rowSet, $singleRow=false) {

        $resultArray = array();

        while ($row = mysql_fetch_assoc($rowSet)) {
            array_push($resultArray, $row);
        }

        if ($singleRow === true)
            return $resultArray[0];

        return $resultArray;

    }

    // Select rows from the database.

    public function select($table, $where) {

        $sql = "SELECT * FROM $table WHERE $where";

        $result = mysql_query($sql);

        if (mysql_num_rows($result) == 1)
            return $this->processRowSet($result, true);

        return $this->processRowSet($result);

    }

    // Update a current row in the database.

    public function update($data, $table, $where) {

        foreach ($data as $column => $value) {
            $sql = "UPDATE $table SET $column = $value WHERE $where";
            mysql_query($sql) or die(mysql_error());
        }

        return true;

    }

    // Insert a new row into the database.

    public function insert($data, $table) {

        $columns = "";
        $values = "";

        foreach ($data as $column => $value) {
            $columns .= ($columns == "") ? "" : ", ";
            $columns .= $column;
            $values .= ($values == "") ? "" : ", ";
            $values .= $value;
        }

        $sql = "INSERT INTO $table ($columns) VALUES ($values)";

        mysql_query($sql) or die(mysql_error());

        return mysql_insert_id();

    }

}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:10:16+00:00Added an answer on May 22, 2026 at 3:10 am

    A few problems I noticed:

    • You run a query in function latestBookmarks before you connect to the db;
    • In your function connect you connect to a database, but the result is discarded immediately, $connection is lost as soon as the function finishes.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have 3 files class.myclass.php test1.php test2.php class.myclass.php contains class myclass { public $value;
I have two files like below SomeClass.php class SomeClass { public function display() {
I have a class class files{ function displayhtml(){?> select name=df> for($i=0;$i<10;$i++){?> <option value=<?php echo
I have a java class that applies an xslt to all xml files in
I have a class file that contains all the classes that are needed for
I have three files: one called sql.php witch has a class db that I
I have read about dynamically loading your class files when needed in a function
I am planning to use PHP's autoload function to dynamicly load only class files
I am using the singleton pattern in all my PHP class files. Would it
I have a php site which flows as shown below. Please note I'm leaving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.