Php noob help


I like that! I like that a lot. Thanks Kabal

OOP is something I really need to start doing, I am just struggling to think of things in a Object manner and before I know it I have a begin middle end approach.
 
no problem

a simple way is to try internalise the Single Responsibility Principal, and always ask yourself things like "Does this really belong here? What is this doing, is this a good name? etc"
 
Extra S in the second one:

private static GET_ITEMS_SQL = "SELECT * FROM items";
private static GET_ITEMS_SQL = "SELECT * FROM items WHERE id = ?";

should be:

private static GET_ITEMS_SQL = "SELECT * FROM items";
private static GET_ITEM_SQL = "SELECT * FROM items WHERE id = ?";
 
no problem

a simple way is to try internalise the Single Responsibility Principal, and always ask yourself things like "Does this really belong here? What is this doing, is this a good name? etc"

I do do that and then I simply add it in a other file and use require or include :P

Right now I am trying to get comfortable with OOP and achieve "least privileged" since I can see from your example some variables and functions should not be accessible to anything other than the function that uses it.
 
That's what I thought.

/moving on.

If this was production and not done in a few minutes of course I would do something like:

PHP:
DELIMITER $$
 
CREATE PROCEDURE GetItem()
BEGIN
 SELECT *
 FROM items;
    END$$

and then

PHP:
$sql = 'CALL GetItem()';

Why would you have completely different, insecure code in dev that will HAVE to change for it to be in production? Link some of your projects I'm (((interested)))
 
Extra S in the second one:

private static GET_ITEMS_SQL = "SELECT * FROM items";
private static GET_ITEMS_SQL = "SELECT * FROM items WHERE id = ?";

should be:

private static GET_ITEMS_SQL = "SELECT * FROM items";
private static GET_ITEM_SQL = "SELECT * FROM items WHERE id = ?";

via Imgflip Meme Generator

:crylaugh:
 
Why would you have completely different, insecure code in dev that will HAVE to change for it to be in production? Link some of your projects I'm (((interested)))
Because this was not a project this was an illustration to the OP of the logical process that must happen for him to display the data and was in no way more than this.
 
Because this was not a project this was an illustration to the OP of the logical process that must happen for him to display the data and was in no way more than this.
I think many miss that point; explanations are best kept simple.
 
I like that! I like that a lot. Thanks Kabal

OOP is something I really need to start doing, I am just struggling to think of things in a Object manner and before I know it I have a begin middle end approach.
You should never fall into the quagmire of trying to envisage eveything as objects; that part of OOP is long considered BS. Design should be kept simple, don't ever build structure you'll probably never need.
 
[)roi(];18691682 said:
You should never fall into the quagmire of trying to envisage eveything as objects; that part of OOP is long considered BS. Design should be kept simple, don't ever build structure you'll probably never need.

this is true.

that is why I didnt go crazy and use a full blown service repository "pattern". all I wanted to do was create a simple abstraction/separation, to make things easier, in my mind, to understand, and potentially expand on if required
 
SQL injection FTW

You can try

PHP:
$stmt = $pdo->prepare('SELECT * FROM items WHERE id = :id');

$stmt->execute(array('id' => $id));

foreach ($stmt as $row) {
    // do something with $row
}
 
this is true.

that is why I didn't go crazy and use a full blown service repository "pattern". all I wanted to do was create a simple abstraction/separation, to make things easier, in my mind, to understand, and potentially expand on if required
Was a suggestion for Thor187; your code was spot on.
 
Why would you create a stored procedure for a simple select. I'd rather have it in code where it's more readable.
 
Why even load that initial table from a DB (that table with the city names)? That is wasteful and should be discouraged. The more you read from the Database, the more resources will be needed. Use JSON and read the table content from the JSON file (just in case it will have to be modified) then use the modal to load the other stuff from the Database.
 
Top
Sign up to the MyBroadband newsletter
X