Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

monstajamss's avatar

How to write OOP Query in PHP

I am trying to write some functions in PHP but just to my surprise i keep getting 500 internal server error.

Here is my code:

<?php

class Surveuillance{
public $id;
public $info;

public function __construct($id)
{
	$this->id = App::escape($id);
	$this->info = App::sql()->query_row("SELECT * FROM userdb");
}

public function display_info()
{
	$id = $this->info->id
	$right = App::sql()->query_row("SELECT * FROM camera WHERE id = '$id");
	return $right;
}

}

Then i did this after importing it in surveillance.php

$survey = Surveillance::display_info()

echo $survey;
0 likes
4 replies
click's avatar
click
Best Answer
Level 35

There is a typo in your code: Surveuillance vs Surveillance

I don't know what kind of code it is as it seems a bit odd to me. But display_info() is also not a static method so you cannot call it like this: Surveillance::display_info(). You can only do it like this:

$surveillance = new Surveillance($id);
$surveillance->display_info() 

And for the rest, your 500 error should give you some more information on what is going wrong in your code. If you do not see it on your screen the error log should give you a more detailed description of what is going wrong.

monstajamss's avatar

@click So will that be

public function display()
{
	$id = $this->info->id
	$right = App::sql()->query_row("SELECT * FROM camera WHERE id = '$id");
	return $right;
}

in the other file

$surveillance = new Surveillance($id);
$surveillance->display_info() 
click's avatar

@monstajamss no, if your method is called display() you should also call it like display() and not display_info()

Sinnbeck's avatar

Can I recommend you turn on php errors so you see the error instead of 500

Please or to participate in this conversation.