Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by benanamen

  1. Interested in feedback regarding turning notices and warnings to exceptions with set_error_handler. To me, if you have warnings or notices the code is broke and needs to be fixed before it goes to production. If the app fatals you know it and HAVE to fix it. Pros? Cons? Manual Reference http://php.net/class.errorexception
  2. It sounds a lot like you have a bad database design. Can you post your DB schema or p.m. it?
  3. Forget the author. Just do (True example. Yours is a false example) If true if($row->mysql_field){ //Do something } This example is also in the manual. Couldn't find the page at the moment. if false (Your example) if(!$row->mysql_field){ //Do something }
  4. Look up and learn Database Normalization.
  5. I just learned Vagrant a few months back. It is actually very simple and is a great tool for it's purpose. The only thing with using the pre-built boxes is you really don't know for sure exactly how it was configured when it was made. The time it takes to download a box, you could just create your own. The pre-mades are good for a quick to get going solution or just trying different OS's. Like @Jaques1 said, just download and install exactly what you want. For additional flexibility you can turn that into a Vagrant box of your own. If you're going to be a developer you need to get on 64 bit. You can't run 64 bit software on 32 bit hardware. For those not familiar with Vagrant, it's worth a look. https://www.vagrantup.com/
  6. From what I have learned of it so far, it seems well suited for real time two way connections using web sockets, which from what I gather from @NotionCommotion's posts and PM's is what he is doing. A node description I read that seems to fit. Of course, I am just starting to learn it which is why a real project would be nice to work with.
  7. As I mentioned in a previous PM, I really think Node.js is a much better tool for what you're doing. (For as much I understand your project). PM me enough working details of what you're doing and I will see what I can do in Node. I know you are not at a place to learn a new "language" right now. It will give me a real example that will help my skills in Node and I will also be able to bumpstart you with learning Node if/when you ever get there.
  8. Benanamen quoted the Manual.
  9. Why are you throwing Javascript in there? Your script will fail if the user turns it off. Use Php's header to do your redirect. Also, do not EVER put variables in your query. You need to use prepared statements. And stop outputting the DB errors to the user. That info is only good to a coder or a hacker. I would suggest you start using PDO. https://phpdelusions.net/pdo
  10. As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of each statement. The closing tag of a block of PHP code automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block. The closing tag for the block will include the immediately trailing newline if one is present. The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include or require, so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files. http://php.net/manual/en/language.basic-syntax.instruction-separation.php The semi-colon at the start of the line is programmer preference. When there are many lines it is very easy to spot a missing one. Pick a style and stick to it. I only see it used for SQL statements.
  11. I explained the problem to you. Because you included thisfile.php in index, it is no different than if you moved thisfile.php out of the includes folder and placed it in the mninfo folder like so xampp/htdocs/mninfo/thisfile.php So the ../ in thisfile.php actually points to xampp/htdocs/ if you want to to point to the mninfo folder, remove one of the dots like so File thisfile.php: require './oldstuff.php';
  12. That is very much clearer and easily understandable. Unfortunately I am done for the night so I can't help you any further right now. I am sure someone will probably give you direction before I can get back to you. In the meantime, get familiar with the XY Problem in my signature. It will help you and us in the future.
  13. You don't need to use the full path. Start from the directory where you are at. I don't know exactly where the file oldstuff resides so I can't show you for sure. When you use ../ from an included file you are going above the main directory mninfo to look for it. I don't think that is where you have it. thisfile.php is effectively where index.php is because you included it to be there. It has "become one" with index.php so it it no different if you added ../oldstuff.php to the index file which in your case takes you to the htdocs folder looking for the file. index.php require './includes/js/common.js'; require './includes/thisfile.php'; require './oldstuff.php';// Assuming this file is in mninfo Also using the full path will not allow you to move your app around without editing the path every time.
  14. What you're doing wrong is not listening to what you were already told. @Barand showed you what to do.
  15. I for one dont understand what your doing. Forget your attempted solution for a minute. Try to describe better what you have and what it needs to do. This reads like you have all those records that will add a row, as in a single row. That doesn't make sense at the moment. Where is the hundred thousand records coming from? Best I can tell is you have three columns, an id, revenue, and date. If the dates have a zero value what date are you going to replace it with? Why do some have a zero for a date in the first place?
  16. Aside from setting a default value, is there any reason a class needs properties or a property with no default value? Here are two examples I am working with. One has a default car color from a property that gets changed (overwritten?), the other just sets the color with no property. Property with default color value <?php class Car { public $color = 'red'; } $bmw = new Car (); echo $bmw -> color; // red $bmw -> color = 'blue'; echo "<br>"; echo $bmw -> color; // blue Class with no property sets color <?php class Car { } $bmw = new Car (); $bmw -> color = 'blue'; echo $bmw -> color; // blue
  17. You are using obsolete code that has been removed from Php. You need to use PDO with prepared statements. You are also vulnerable to an SQL Injection Attack. You never ever use variables in your query. The entire thing needs to be tossed. https://phpdelusions.net/pdo
  18. Look at your first if. Your POST is wrong. $POST should be $_POST
  19. If you don't see it, it is because I don't know to do it, otherwise it would be there. So perhaps that is actually the next part I need to learn about. I don't know about attributes holding state in OOP. I don't know about autonomously taking care of tasks in OOP. What can you tell me about that in a way I can understand? At this point, I don't know enough to make decisions of how I would personally want to implement anything in OOP. I am looking for the definitive way to do things for as much as that is possible. One of the things I don't like about Php is there is just way too many ways to do the same exact thing. One of the things I liked about implementing interfaces is it is definitive in that if you don't use the methods, it doesn't work. It is a strict rule.
  20. I think you are not understanding my approach. I know there is much more to be done. I am basically taking this a piece at a time to make sure I am getting that piece correct and trying to avoid information overload. What you see "left over" in procedural is what are the next steps to understand in OOP correctly. For a DB, making a connection is step one. Now obviously I need to learn the proper way to handle CRUD. When I ask you questions, it is not to question what you tell me, it is to understand the "why" and not just to know that's what I should do. e.g I know to turn on a light you flip the switch and the light comes on, but I want to know "why" it does. You can't really be a Master of something if you don't know it inside and out. That is not my intent despite what the readme on my repo says. There is a particular reason it was worded like that. My intent is to re-write that project in complete, optimum OOP best practices. I have read numerous car, bicycle, animal, and people OOP tutorials and am familiar with what they all said. How much is correct or could be better, I have no idea as of now. So, you know my project, you know what my intent is, and you can see the code at my repo that I am transforming to OOP. If you're willing, that should make it easy to guide me, I am more than willing to put in the time to learn and understand what you tell me. So, yes, I do want to learn OOP, but I want to learn it correctly from the start. Moving forward, it seems my next steps are to do something with the CRUD operations. And yes, I have read many a code that others have done which just appears they are probably doing it wrong since none of them do it near the same way. My question is, would the CRUD operation for a particular DB type (e.g Mysql) go in the class that implements the connection or is there some super crud class design that any type of db can use? Additionally, since you could be using two DB's at once (Mysql & MongDB), how should the actual credentials be set up? Thanks to all who help!
  21. Your code is vulnerable to an SQL Injection Attack. You never ever put variables in a query. You need to use prepared statements. It is also a security problem outputting DB errors to the user. That info is only good to a programmer or a hacker. I suspect you have many other problems as well.
  22. Where is the array coming from? A Database? How is the data getting like that in the first place?
  23. Looking into it, that looks like what I needed to know about. I see Active Record is a pattern as well as an Open Source ORM library. Which one are you referring to? Is the pattern something I should learn how to write myself or do I just use the library? This works exactly as expected. Any issues with it? Since this works, why would I need a Data Mapper or Active Record mapper? <?php interface Database { public function connect(); } //---------------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------------- class Mysql implements Database { public function connect() { $dsn = DB_TYPE . ":host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET; $opt = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; return new PDO($dsn, DB_USER, DB_PASSWORD, $opt); } } //---------------------------------------------------------------------------------------- // Testing //---------------------------------------------------------------------------------------- $db = new Mysql(); $pdo = $db->connect(); $sql = 'SELECT login_username FROM user_login'; $stmt = $pdo->prepare($sql); foreach ($pdo->query($sql) as $row) { echo $row['login_username']; }
  24. The short answer to what I am doing is converting the procedural code from my repo to OOP for the sole purpose of learning advanced OOP. For as much as is possible, I want to write the "perfect app" in OOP.
  25. As mentioned in another thread, all the OOP questions are for learning the proper way to do OOP. The test project only consists of registration/login/forgot password/password reset functionality so that would tell you what all my questions will relate to. When I post something that doesn't make sense in relation to that functionality it is because that is the best I currently understand to do in OOP so knowing what the "project" consists of should make it easy for someone to guide me and point me in the proper direction. I could read about how to do OOP all day on the net but I don't know enough yet to know if the author knows what they are talking about so I look to the couple experts on this forum that I trust and know have the proper knowledge. When I see certain procedural code I can spot in an instant if the author knows anything. i.e vars in a query, mysql_* functions. In OOP I currently can only spot if they use var or it looks like the class does a lot of things. So to answer your question (which knowing the project should make obvious) 1. I want a person to be able to register for the app 2. Validate their email address from a secure token 3. Be able to login and logout 4. Submit a "forgot password" request 5. Reset the password from a token emailed So this deals with a database, authentication, sessions etc, the usual stuff you already know. I have done this hundreds of times in procedural. For the OOP version, it should be easily scalable to other implementations such as different DB's, different logging mechanisms, etc, etc. What you taught me about interfaces was a HUGE bump in the right direction. I would have been flopping around with abstract classes or something less important if it wasn't for you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.