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 7557853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:14:24+00:00 2026-05-30T12:14:24+00:00

I am working with a MySQL Database and having some issues while trying to

  • 0

I am working with a MySQL Database and having some issues while trying to get data from several built-in PHP MySQL methods. I have written a class to interact with the database, and here are the relevant bits:

<?php
include("includes/Config.inc.php");
include_once("ChromePHP.class.php");
class Database{
    private $db;
    private $hostname;
    private $username;
    private $password;
    private $schema;

    function __construct() {
        if(func_num_args() == 0){
            $this->hostname = conf_hostname;
            $this->username = conf_username;
            $this->password = conf_password;
            $this->schema = conf_schema;
        }
        else{
            $params = func_get_args();
            $this->hostname = $params[0];
            $this->username = $params[1];
            $this->password = $params[2];
            $this->schema = $params[3];
        }
        $this->open();
    }

    private function open(){
        $this->db = mysql_connect($this->hostname, $this->username, $this->password) or die ('Error connecting to mysql');
        mysql_select_db($this->schema, $this->db);
        mysql_query("SET NAMES utf8");
    }

    public function executeQuery($query){
        $results = mysql_query($query, $this->db) or die ("Error in query: $query. ".mysql_error());
        return $results;
    }

    public function executeNonQuery($query){
        mysql_query($query, $this->db) or die ("Error in query: $query. ".mysql_error());
        $info = mysql_info($this->db);
        if($info){
            $bits = explode(' ', $info);
            return $bits[4];
        }
        return false;
    }

    public function close(){
        mysql_close($this->db);
    }


    public function escape($string){
        $output = mysql_real_escape_string($string , $this->db);
        return $output;
    }

    public function getRegionTree(){
        $query = "SELECT COUNT(parent.Name) - 2 as level, node.Name AS Name, node.ID, node.Parent
                    FROM Region AS node, Region AS parent
                        WHERE node.LeftVal BETWEEN parent.LeftVal AND parent.RightVal and node.Name <> 'Earth'
                            GROUP BY node.ID
                            ORDER BY node.LeftVal";
        $result = $this->executeQuery($query);
        $last_level = 0;
        $output = '<ul id="regionTree">'.PHP_EOL;
        while ($row = mysql_fetch_assoc($result)) {
            $link = '<li>'.PHP_EOL.'<a href="#" data-self="'.$row["ID"].'" data-parent="'.$row["Parent"].'">'.$row["Name"]."</a>".PHP_EOL;
            $diff = $last_level - $row["level"];
            if($diff == 0){
                // Sibling
                $output .= ($row["level"] != 0) ? '</li>'.PHP_EOL.$link:$link;
            }
            elseif($diff < 0){
                // Child
                $demoter = '<ul>'.PHP_EOL;
                for ($i=0; $i > $diff; $i--) { 
                    $output .= $demoter;
                }
                $output .= $link;
            }
            else{
                // Parent
                $promoter = '</li>'.PHP_EOL.'</ul>';
                for ($i=0; $i < $diff; $i++) { 
                    $output .= ($row["level"] != 0) ? $promoter.PHP_EOL."</li>":$promoter;
                }
                $output .= $link;
            }
            $last_level = $row["level"];
        }
        $output .= "</li></ul>";
        return $output;
    }

    public function addRegion($name, $type, $parentID){
        $query = "select Name, Region_Type from Region where ID = ".$parentID;
        $result = $this->executeQuery($query);
        if($result){
            $row = mysql_fetch_assoc($result);
            $query = "call AddRegion('".$name."', '".$type."', '".$row["Name"]."', '".$row["Region_Type"]."', @returnCode, @returnMessage)";
            $result = $this->executeQuery($query);
            if($result){
                return true;
            }
            else{
                $query = "select @returnCode as code, @returnMessage as message";
                $result = $this->executeQuery($query);
                while($row = mysql_fetch_assoc($result)){
                    print_r($row);
                }
                return false;
            }
        }
        return false;
    }

    public function getInfo(){
        return mysql_info();
    }

    public function editRegion($id, $name, $type){
        $query = "update Region set Name = '$name', Region_Type = '$type' where ID = $id";
        if($this->executeNonQuery($query) > 0){
            return true;
        }
        return false;
    }
}
$db = new Database();
?>

With this Database class I am able to successfully make queries, get region trees, and successfully change data in the database using the ExecuteNonQuery function. However, any attempts I have made to use mysql_info, mysql_affected_rows, or other similar functions fails, making it really difficult to write any error handling code. To make matters stranger yet, if I run the following code:

<?php
    $db = mysql_connect("localhost", "User", "Password") or die ('Error connecting to mysql');
    mysql_select_db("DB", $db);
    mysql_query("update Region set Name = 'test' where ID = 594", $db);
    echo mysql_info($db);
?>

I am able to get results as expected. Any Ideas?

  • 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-30T12:14:25+00:00Added an answer on May 30, 2026 at 12:14 pm

    After adding “or die()” statements in several places in my script, I was surprised to see that nothing was actually failing to work, instead it was failing to work the way I expected it to. The problem I was having as it turns out, was that splitting the output of mysql_info (on the space character) resulted in several indices in the array containing nothing, as would be generated by inconsistent whitespace in the output of mysql_info. The index that I thought (based upon counting spaces visually) would contain an integer instead contained a string, and I was attempting to compare that string against the number 0, which won’t work. I have updated my executeNonQuery function as follows:

    public function executeNonQuery($query){
            mysql_query($query, $this->db) or die ("Error in query: $query. ".mysql_error());
            $info = mysql_info($this->db);
            if($info){
                $output = array();
                $bits = explode(' ', $info);
                $output["rowsMatched"] = $bits[2];
                $output["rowsChanged"] = $bits[5];
                $output["warnings"] = $bits[8];
                return $output;
            }
            return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a MySQL database that has some data imported from Excel .
I'm trying to insert some data into my mysql database. The connection is working
I'm working on a script in PHP that needs to get some info from
I am trying to retrieve data from MySQL for a flash application via PHP,
I am working on having data taken from a form submit to a database,
I am working with a rather large mysql database (several million rows) with a
I'm currently working on a PHP application that uses a MySQL database for its
I'm having some trouble updating a row in a MySQL database. Here is the
I'm working on a java 2ME app that submit data to mysql database (am
I am working on table that prints addresses from a MySQL database. I'm not

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.