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

  • SEARCH
  • Home
  • 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 7653447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:02:17+00:00 2026-05-31T12:02:17+00:00

I have another PHP question for you. I have a class that is supposed

  • 0

I have another PHP question for you. I have a class that is supposed to go into a database and find labels which will be used in the main program file. When I try to connect to my database, it seems to not like the fact that I’m using a function to set the value of a variable (I am guessing that’s why I has the “unexpected (” error)

Here is the class:

class lblFinder
        {
            //declarations
                private $dbConnection=mysql_connect("localhost", "root", "");
                private $dbName="matecalculator";

                private $cmd="";
                private $size=0;
            //end of declarations

            public function setSize($shape)
            {
                if($dbConnection===false)
                {
                    echo "<p>Something went wrong.</p><p> Error Code:".mysql_errno().": ".mysql_error()."</p>";
                }
                else
                {
                    if(mysql_select_db($this->dbName,$this->dbConnection))
                    {
                        $cmd="SELECT COUNT(varID) FROM tblVariables WHERE shapeID IN(SELECT shapeID FROM tblShapes WHERE shapeName= '".$shape."')";
                        $qryResults=mysql_query($this->cmd,$dbConnection);

                        //get results
                        while (($Row = mysql_fetch_row($QueryResult)) !== FALSE)
                        {
                            $size=$Row[0];
                        }

                        mysql_free_result($qryResults);
                    }
                    else
                    {
                        echo "<p>Something went wrong.</p><p> Error Code:".mysql_errno().": ".mysql_error()."</p>";
                    }
                }
            }

            public function getSize()
            {
                return $this->size;
            }

            public function setLabels($shape)
            {
                //declarations
                    $l=array();
                //end of declarations

                $this->cmd="SELECT varDesc FROM tblVariables WHERE shapeID IN(SELECT shapeID FROM tblShapes WHERE shapeName= '".$shape."')";
                $qryResults=mysql_query($cmd,$dbConnection);

                $i=0;
                if(($Row = mysql_fetch_row($QueryResult)) !== FALSE)
                {
                    $l[i]=$Row[0];
                    $i++;
                }
                mysql_free_result($qryResults);
                return l;
            }
        }

I use a test file to pass dummy values to the application. The relevant code is as follows:

        $arr=array();
        $lf=new lblFinder;
        $lf->setSize("Round");
        echo "Size=".$lf->getSize();
        $arr=$lf->setLabels("Round");
        $i=0;
        foreach($arr AS $label)
        {
            echo "Label $i is $label";
        }

I know that “Round” is a valid value in my DB. I also know that my logic works, because I built this exact app in ASP.NET, and it worked (unfortunately the client didn’t tell us asp wouldn’t work until after it was written…so I need to use PHP)

The functioning ASP code is as follows

 public class lblFinder
 {
private static string connectionString;
private MySqlConnection con;
private MySqlCommand cmd;
private MySqlDataReader reader;
private int size;
private int i = 0;

public lblFinder(string connStr, MySqlConnection connection, MySqlCommand c, MySqlDataReader r)
{
    connectionString = connStr;
    con = connection;
    reader = r;
    cmd = c;
    cmd.Connection = con;
}

public void setSize(string shapeName)
{
    cmd.CommandText = "SELECT COUNT(varID) FROM tblVariables WHERE shapeID IN(SELECT shapeID FROM tblShapes WHERE shapeName= '" + shapeName + "')";
    reader = cmd.ExecuteReader();
    if (reader.Read())
    {
        size = reader.GetInt32(0);
    }
    reader.Close();
}

public int getSize()
{
    return size;
}

public string[] setLabels(string[] l, string shapeName)
{
    i = 0;

    cmd.CommandText = "SELECT varDesc FROM tblVariables WHERE shapeID IN(SELECT shapeID FROM tblShapes WHERE shapeName= '" + shapeName + "')";
    reader = cmd.ExecuteReader();

    while (reader.Read())
    {
        l[i] = reader.GetString("varDesc");
        i++;
    }
    reader.Close();

    return l;
}
}
  • 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-31T12:02:19+00:00Added an answer on May 31, 2026 at 12:02 pm

    In your variable declaration, you cannot call a function.

    private $dbConnection=mysql_connect("localhost", "root", "");

    Instead, use a constructor:

    private $dbConnection;
    function __construct() {
      $this->dbConnection=mysql_connect("localhost", "root", "");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main class which initializes another class in a function of main
I have a PHP script that I'm invoking from another shell script that sends
I have a webpage that redirects to another webpage like this: http://www.myOtherServer.com/Sponsor.php?RedirectPage=http://mylink.com/whereIwasgoingtogo.html Then the
PHP mysql database I have created a follow on question to this one here
I have another question, not sure if this would be accomplished via PHP or
I recently plugged memcaching into my PHP web software. I have a class, Cache,
Below is part of a PHP database class someone else wrote, I have removed
I have a class that has a function, lets say class.php: class fun {
I have created a form in which i embed another form. My question is
I want to have a PHP script send a XML formatted string to another

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.