Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,162,776 members, 7,851,641 topics. Date: Thursday, 06 June 2024 at 02:57 AM

Why Is OOP PHP So Confusing? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Why Is OOP PHP So Confusing? (6812 Views)

Learn Object Oriented Programming (OOP) AT SANDCROFT SOFTWARE / After 5 Months Of Learning OOP In Visual C#-here Is A Little Project I Made. / I Want To Learn Php Oop! Prescribe An Ebook (2) (3) (4)

(1) (2) (Reply) (Go Down)

Why Is OOP PHP So Confusing? by Nobody: 11:53am On Feb 14, 2016
Yesterday, a chairman/owner of about 20 hotels in my environs called me and told me to develop a system that will help him monitor the financial activities in his hotels.

So I decided to build a mini hotel management portal for him that will run across the multiple hotels.

I did and finished my basic designs with Bootstrap (copied some design pattern from another site). So I started doing some backend development using PHP MySQLi procedural.
I was already halfway through the system development, so I realized that MySQLi procedural shouldn't be my route because the system will constantly undergo series of multiple queries.

"This kind if system should be scalable and robust", This was my thoughts, so I decided to Google OOP PHP MySQLi v PDO performance, which took me to this small article by the PHP blogger.


http://wooptoo.com/blog/pdo-vs-mysqli-performance-comparison/

from the guys article PDO was better in terms of performance.

So I decided to start rewriting my PHP code using PDO. "For the fact that I know Java at an Intermediate level, it shouldn't be a problem for me to start writing OOP with PDP", so I thought. but this is not the case, because OOP PHP is quite confusing especially using PDO.

I was thinking, it has same paradigm with normal OOP like Java and C/C++, but it is a little different.

I'm very determined to build this system using PDO because I want outmost satisfaction to the hotel owner.

Any tips, suggestion or help that can help fast trap my development time.

Thank you and God bless.

Happy Valentine.
Re: Why Is OOP PHP So Confusing? by APO(f): 12:48pm On Feb 14, 2016
i think for fast delivery use mysqli that you are familiar with, try to structure your tables well and index every table with about 3 or 4 indexes. Before the processes get too serious while the client is already satisfied with the software you could figure out the PDO better

1 Like

Re: Why Is OOP PHP So Confusing? by Nobody: 12:49pm On Feb 14, 2016
I read all the post by the way, well, what I can safely tell you is that since you are already familiar with MySQLi, what you need is a very good and scalable wrapper.
You can checkout my own home-made wrapper here which i have used for a good number of big projects including a real-time chat android app.
https://www.nairaland.com/2870586/dhtmlsql-very-advanced-wrapper-mysql

Then, you should also consider using persistent connection in mysqli.
Re: Why Is OOP PHP So Confusing? by Nobody: 1:05pm On Feb 14, 2016
APO:
i think for fast delivery use mysqli that you are familiar with, try to structure your tables well and index every table with about 3 or 4 indexes. Before the processes get too serious while the client is already satisfied with the software you could figure out the PDO better

Like I said, "I am very determined"

I want to learn how to use it as well.
Re: Why Is OOP PHP So Confusing? by Nobody: 1:06pm On Feb 14, 2016
dhtml18:
I read all the post by the way, well, what I can safely tell you is that since you are already familiar with MySQLi, what you need is a very good and scalable wrapper.
You can checkout my own home-made wrapper here which i have used for a good number of big projects including a real-time chat android app.
https://www.nairaland.com/2870586/dhtmlsql-very-advanced-wrapper-mysql

Then, you should also consider using persistent connection in mysqli.

thanks Sir. I will surely look at it.
Re: Why Is OOP PHP So Confusing? by Adesege(m): 1:11pm On Feb 14, 2016
Hello, what I do when i was still using the procedural method is to create functions for queries I will be using often.

For example, to get users in a database, I would create something like this:

function users($where=NULL){
if(!empty($where)){


$sql=mysqli_query("SELECT * FROM users WHERE $where",$conn);

if(mysqli_num_rows($sql)>0){
return mysqli_fetch_assoc($sql);
}
return;
}
}

Then u get a particular user with

$user=users('id='.$user_id.'');

To get all users,

$users=users();

You can loop through using while, foreach or for loops.

You can alternatively use Codeigniter, you will definitely love it if you consider using it.

You can configure it to use themes and smarty. You can also use HMVC with it.

You can as well follow APO's advice.

Let me know if this helps.

**modified**

The function above is just an illustration, I cant guarantee if it will work cos it's not tested.
Re: Why Is OOP PHP So Confusing? by Nobody: 1:15pm On Feb 14, 2016
Adesege:
Hello, what I do when i was still using the procedural method is to create functions for queries I will be using often.

For example, to get users in a database, I would create something like this:

function users($where=NULL){
if(!empty($where)){


$sql=mysqli_query("SELECT * FROM users WHERE $where",$conn);

if(mysqli_num_rows($sql)>0){
return mysqli_fetch_assoc($sql);
}
return;
}
}

Then u get a particular user with

$user=users('id='.$user_id.');

To get all users,

$users=users();

You can loop through using while, foreach or for loops.

You can alternatively use Codeigniter, you will definitely love it if you consider using it.

You can configure it to use themes and smarty. You can also use HMVC with it.

You can as well follow APO's advice.

Let me know if this helps.

Thanks bro, I haven't really learnt any PHP MVC, I think this is not the best time to do so considering the time I have to deliver my final system to my client.

I appreciate, your advice though.
Re: Why Is OOP PHP So Confusing? by Adesege(m): 1:21pm On Feb 14, 2016
GetAvenue:


Thanks bro, I haven't really learnt any PHP MVC, I think this is not the best time to do so considering the time I have to deliver my final system to my client.

I appreciate, your advice though.

Codeigniter is a framework so what you basically need is a basic knowledge of PHP. You don't need to know MVC but a basic knowledge wont be bad.

Also, if security is of essence to you, I would suggest you give codeigniter a try.
Re: Why Is OOP PHP So Confusing? by Nobody: 3:44pm On Feb 14, 2016
GetAvenue:


Thanks bro, I haven't really learnt any PHP MVC, I think this is not the best time to do so considering the time I have to deliver my final system to my client.

I appreciate, your advice though.
Let me mention something at this point. The person asking you to do MVC is correct, because if you do this thing the procedural way, the project may hang now or in the future.
But well, you are doing a race against time thing, i wish you the best. I have been in your shoes before.

But one fact you should consider is outsourcing this stuff, reason - this stuff requires a senior level php/mysql programmer.
Re: Why Is OOP PHP So Confusing? by ChinenyeN(m): 3:49pm On Feb 14, 2016
What exactly is confusing about PHP's implementation of OOP? You've got classes, constructors, private, public and protected variables and methods, inheritance and interfaces. At the very basic level, it's not that different. But I guess I can understand a little. PHP is still a procedural language, despite its additional OOP features. So, it could feel strange having to deal with it.

I would say try dhtml18's wrapper first, before trying to incorporate any framework. I've come to find out in my experience that I often don't need frameworks, because I can implement most of what I may need without said frameworks. The only potential issue I can conceive of would be scalability and security. In which case, it really is mostly all about planning ahead as best you and critical thinking while you design the system architecture.

I'd say that even as you try to use OOP, take full advantage of PHP's procedural nature. Keep a separate script for configuration, a separate script for function definitions. Don't confine all your functions as object methods, especially if you intend to use these functions in a much broader scope or can anticipate using them in a much broader scope. Then have all active scripts require an initialization file that basically gives them access to those function definitions. That is probably the simplest and most straightforward first step that I would recommend for scalability.

Besides that, I would say do what you're comfortable with and what you believe will work for your situation. After all, it is your project and your handiwork. Whatever you implement has to make sense to you that way you could modify it in the future. Good luck.

1 Like 1 Share

Re: Why Is OOP PHP So Confusing? by talk2hb1(m): 7:25pm On Feb 14, 2016
dhtml18:

Let me mention something at this point. The person asking you to do MVC is correct, because if you do this thing the procedural way, the project may hang now or in the future.
But well, you are doing a race against time thing, i wish you the best. I have been in your shoes before.
But one fact you should consider is outsourcing this stuff, reason - this stuff requires a senior level php/mysql programmer.
I think Framework is a NO! NO!! for this guy, he is finding it difficult handling mere mysqli object, he will faint understanding the concept of MVC wink
As suggested above use the DHTML Library I think that has help solve your Database manipulation by 80% cheesy
Re: Why Is OOP PHP So Confusing? by Nobody: 7:30pm On Feb 14, 2016
^^^Exactly, the framework should help him. It was designed for my own framework actually, but I also made it a standalone version for purposes like this. It is very secure and heavily documented.
Re: Why Is OOP PHP So Confusing? by sleepingdemon: 8:34pm On Feb 14, 2016
dhtml18:
I read all the post by the way, well, what I can safely tell you is that since you are already familiar with MySQLi, what you need is a very good and scalable wrapper.
You can checkout my own home-made wrapper here which i have used for a good number of big projects including a real-time chat android app.
https://www.nairaland.com/2870586/dhtmlsql-very-advanced-wrapper-mysql

Then, you should also consider using persistent connection in mysqli.

i was about to talk, but oga dhtml has come with his wraper again, however i would want to agree with the guy that mentioned codeigniter, its way light, suitable for what you would love to do, you would also learn it under a week i guess, since youre familiar with php, and it would help you to enjoy oop php.
--
Re: Why Is OOP PHP So Confusing? by Nobody: 8:53pm On Feb 14, 2016
Codigniter is the best for this kind of problem. But if it is just a database thing, then my wrapper will work.
By the way, my wrapper can be used in codigniter. . . .
Re: Why Is OOP PHP So Confusing? by Nobody: 9:29pm On Feb 14, 2016
Thanks guys. My phobia for OOP PHP was as a result of strange OOP syntax, OOP MySQLi would have been better, but OOP PDO nearly killed me.

But right now, I'm making significant progress, because this thing is pretty easy compare to even MySQLi procedural.

By the end of tomorrow, this system will surely be ready.

DHTML I guess your wrapper does not work with PDO?
Re: Why Is OOP PHP So Confusing? by Nobody: 9:45pm On Feb 14, 2016
No, my library is a wrapper for MySQLi and has nothing to do with PDO.
Re: Why Is OOP PHP So Confusing? by sleepingdemon: 10:53pm On Feb 14, 2016
dhtml18:
Codigniter is the best for this kind of problem. But if it is just a database thing, then my wrapper will work.
By the way, my wrapper can be used in codigniter. . . .
let me just ask this important question for me here, does ur wrapper in any mode or way support mysql replication. i.e the master-slave replication where it selects random sql slave servers for read queries and uses the master for only insert, updates and deletes
Re: Why Is OOP PHP So Confusing? by danvery2k6(m): 11:09pm On Feb 14, 2016
PDO is far superior to any wrapper over mysqli you will find over there, besides the fact it's queries are optimised, you also have the advantage od switching databases without worrying about your queries. If I would suggest any other thing, I'll ask you try out Eloquent if you had the time, but then again the learning curve for eloquent is not very steep. In the light of these, I will suggest you read the databases chapter of this book http://it-ebooks.info/book/2241/. It treats PDO in detail. You can take a look at the other chapters if yow want to get a grasp of OOP too.
Re: Why Is OOP PHP So Confusing? by Nobody: 4:51am On Feb 15, 2016
You people on this thread are tiring me with questions, and I guess I shall stop answering them.
See guys, it is a free world, and anyone can use whatever they like, my wrapper is well documented - see it here - www.dhtml.github.io/dhtmlsql
It seems to me like many people on this thread do not really seem to understand what a wrapper is?
jQuery is a wrapper for javaScript. So essentially, jQuery does the same thing as javaScript but in a more elegant manner. So someone should not start asking if jQuery is more powerful than JAVA (because that is completely out of it).
I will say it once again, MY WRAPPER SUPPORTS EVERY KNOWN MYSQLI FEATURE AND HAS NOTHING TO DO WITH PDO.

danvery2k6:
PDO is far superior to any wrapper over mysqli you will find over there, besides the fact it's queries are optimised, you also have the advantage od switching databases without worrying about your queries. If I would suggest any other thing, I'll ask you try out Eloquent if you had the time, but then again the learning curve for eloquent is not very steep. In the light of these, I will suggest you read the databases chapter of this book http://it-ebooks.info/book/2241/. It treats PDO in detail. You can take a look at the other chapters if yow want to get a grasp of OOP too.
Did you properly read the question? the OP seems to be finding it hard to use PDO (PDO is object-oriented). So this PDO is stronger than MySQLi does not even come to it at all.

Truth is, this project would have been best handled by a framework like codigniter but again OP seems scared of PHP OOP and I wonder why.
Re: Why Is OOP PHP So Confusing? by guru01(m): 10:00am On Feb 15, 2016
@OP,
PDO is not faster than mysqli because PDO uses mysqli when connecting to the database.
OOP is not hard and difficult to understand, but at times there is some kind of fear in us not to forgot what we have learnt just because there is a better or new solution out there.
I have a simple database model i use with my framework when building and kind of app, i can give you just the model to use and guide you through it if you are interested.
It has all the logic in working with database whether you want to use mysqli or pdo.

1 Like

Re: Why Is OOP PHP So Confusing? by Nobody: 10:18am On Feb 15, 2016
guru01:
@OP,
PDO is not faster than mysqli because PDO uses mysqli when connecting to the database.
OOP is not hard and difficult to understand, but at times there is some kind of fear in us not to forgot what we have learnt just because there is a better or new solution out there.
I have a simple database model i use with my framework when building and kind of app, i can give you just the model to use and guide you through it if you are interested.
It has all the logic in working with database whether you want to use mysqli or pdo.

Please explain the bolded. thanks
Re: Why Is OOP PHP So Confusing? by guru01(m): 10:26am On Feb 15, 2016
GetAvenue:


Please explain the bolded. thanks
PDO is a wrapping library for multiple database drivers, including mysqli.
Re: Why Is OOP PHP So Confusing? by Nobody: 1:16pm On Feb 15, 2016
guru01:
@OP,
PDO is not faster than mysqli because PDO uses mysqli when connecting to the database.
OOP is not hard and difficult to understand, but at times there is some kind of fear in us not to forgot what we have learnt just because there is a better or new solution out there.
I have a simple database model i use with my framework when building and kind of app, i can give you just the model to use and guide you through it if you are interested.
It has all the logic in working with database whether you want to use mysqli or pdo.
I do not agree, conventional tests show that PDO is actually faster than MySQLi.
PDO does not use MySQLi at all, nothing like that. PDO has MySQL driver and can connect to MySQL database.

MySQLi is a wrapper only for MySQL while PDO is a wrapper for MySQL and other databases.

1 Like

Re: Why Is OOP PHP So Confusing? by FrankLampard: 3:00pm On Feb 15, 2016
DHTML I tire for some people.

From this article PDO uses PDO MySQL extension when connecting to MySQL database.


http://php.net/manual/en/mysqli.overview.php

The MySQLi extension is a different extension on it's own.
Re: Why Is OOP PHP So Confusing? by maekhel(m): 3:09pm On Feb 15, 2016
A thing I have noticed about nairalabd programmers that their level of oversabi. Always retrying to impress (as if they are in some kind of competion) even at the cost of passing wrong info.
Re: Why Is OOP PHP So Confusing? by Nobody: 5:44pm On Feb 15, 2016
FrankLampard:
DHTML I tire for some people.

From this article PDO uses PDO MySQL extension when connecting to MySQL database.



The MySQLi extension is a different extension on it's own.
#fact

maekhel:
A thing I have noticed about nairalabd programmers that their level of oversabi. Always retrying to impress (as if they are in some kind of competion) even at the cost of passing wrong info.
Exactly, and even fighting to make their points - even when they are not helping the OP.
Re: Why Is OOP PHP So Confusing? by guru01(m): 10:04pm On Feb 15, 2016
@dhtml18 I agree with you.
Pdo can connect do several databases via database extensions. And it practically as fast as mysqli. But mysqli has more support for mysql database than pdo.
Re: Why Is OOP PHP So Confusing? by Nobody: 10:45pm On Feb 15, 2016
I am trying to help the OP not to argue on which one is better between mysqli and pdo.
Re: Why Is OOP PHP So Confusing? by guru01(m): 11:06am On Feb 16, 2016
dhtml18:
I am trying to help the OP not to argue on which one is better between mysqli and pdo.
Same goes for me too.
Re: Why Is OOP PHP So Confusing? by seunthomas: 12:11pm On Feb 16, 2016
Use a framework. It has experience behind it, the more popular the community the better for you. It does not make sense to be fighting "maximum connection errors","Mysql has gone away" errors when we have very good frameworks that would do it more efficiently under heavyload.
Re: Why Is OOP PHP So Confusing? by Nobody: 12:26pm On Feb 16, 2016
seunthomas:
Use a framework. It has experience behind it, the more popular the community the better for you. It does not make sense to be fighting "maximum connection errors","Mysql has gone away" errors when we have very good frameworks that would do it more efficiently under heavyload.
Very amateurish statement, so those that build the framework are not programmers like you? Do you not have something in your GREAT library that can help the poor OP? Especially with all your silly big-boy talks on my thread attempting to rubbish my library (which can actually help the op) on the other thread?
Oya go and start browsing google to look for answers to help the OP, and stop talking big for nothing. . . .them say empty barrels make the loudest noise.
But me i will say this one - All talks and no codes makes a dull programmer.
I just invented that phrase just now specifically to describe dudes like you.

Let me correct that:
All talks and no codes makes a very dull programmer. . . .
Re: Why Is OOP PHP So Confusing? by sinequanon: 2:00pm On Feb 16, 2016
GetAvenue:


Thanks bro, I haven't really learnt any PHP MVC, I think this is not the best time to do so considering the time I have to deliver my final system to my client.

I appreciate, your advice though.

MVC is not a luxury. It is a fundamental paradigm specially designed for scalability. If you do not understand MVC, you have probably bitten off more than you can chew.

1 Like

(1) (2) (Reply)

What PHP Cms/framework Do You Use And Why? / How To Design School Result Sheet Automated System With Microsoft Excel / MCSE: How Many Exams To Write?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 70
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.