Jump to content

gizmola

Administrators
  • Posts

    5,959
  • Joined

  • Last visited

  • Days Won

    146

Everything posted by gizmola

  1. One other comment that might help you here: As far as I know, there isn't a built in extension to woocommerce that handles VAT, so if you are using some module/extension to provide this, that would be important to specify here. There are various different modules available from what I've seen.
  2. Please use the code block for any future posts. Hopefully someone with woo commerce experience will see your post.
  3. The world of php when simple scripts like this were copy and paste jobs is long gone now. The libraries requinix mentioned are certainly the way to go, but also typically require the use of the php dependency management tool composer, and a basic understanding of object oriented programming, in that these libraries are oop. There is also the question of email deliverability. These days, you really need to understand a good deal about how email works, and the various ways email is authenticated, or you can end up with a script that will send emails only to have them rejected or black-holed, or spam filtered, defeating the entire purpose of your endeavor. I'm sorry to say that this is just beyond what a neophyte can handle competently.
  4. You 100% want to write this as a cli application, and do not want to run it as a web application. Cron used to be the way that people scheduled this type of thing, but with modern linux os's services now run under systemd. Kicken provided a great example of how to write a systemd unit file. With that said, you will probably want to read this thread for more information on the format of the files and various capabilities. https://unix.stackexchange.com/questions/224992/where-do-i-put-my-systemd-unit-file I would suggest you start with what kicken provided, and read through the thread to answer questions that might come up, in terms of where to put the file. Systemd has a lot of complexity to it, compared to the things it was designed to replace. There are features that take care of issues that used to come up with services like semaphores to prevent race conditions, which used to be left to developers to code around (typically with shell scripts) and systemd now takes care of that problem for you, if you use the correct configuration. As you should note from the example Kicken provided, there is "Restart=on-failure" which takes care of the problem of your chatbot dying and will restart it.
  5. gizmola

    Greetings!

    The commonality of most frameworks, is that most of them are built using Object orientated design patterns, typically implementing the "Model View Controller" (MVC) pattern. The model layer, when using a relational database is also an ORM. Symfony (and Laravel) are also frameworks, where the underlying pattern of library design is known as "Dependency Injection" (DI). A big benefit in using Symfony or Laravel, is that they facilitate the use of components as services, and you also can easily write your own classes that can be used as services. A quick example, that is frequently needed would be email services in the application. Typically you add the mailing component library to your project, do a bit of config (and in many cases the basic config gets added for you if you use a symfony recipe package) and at that point actually using the library is trivial. The "Dependency Injection Container" that comes with symfony can make decisions on when to load a library that is required (or not). It is thus important to learn something about DI design for use in your own classes. The originator/project lead of Symfony wrote these articles back in 2009, and I still recommend them to anyone trying to understand Dependency injection as a pattern. Read here -> http://fabien.potencier.org/what-is-dependency-injection.html Once you have more comfort with Oop, and at least a basic appreciation of the existence of OOP design patterns, you will have a lot more comfort using any framework. People who really are just trying to wade through a sophisticated framework without any understanding of how/why, can easily get lost, or have the feeling of not knowing what to do when they encounter an issue. With that said, here's a solid free course in Symfony 6, which if you can follow it, you will give you a good foothold in Symfony: I am a long time Symfony user, going back to symfony 1, and the earliest versions of symfony 2. Symfony 1 was an entirely different framework, and 2 was a very influential ground up rewrite that was intended to be a Dependency Injection framework from the start. Almost every major component from Doctrine to Twig was based upon the existence and design philosophy of some other popular library from the Java world or in the case of Twig, from Python's Jinja and Django projects. In most cases all frameworks start with models (the data persistence in a database) and routing configuration into controllers. Views are "templates". This is where you concentrate your markup code where appropriate. Beyond that, a lot of the really good stuff in Symfony or Laravel is in handling of dependency injection, and in providing for features like "event handling" or "security" or "form building and handling". Really smart people have worked on these frameworks and generally use well known and applicable object oriented design patterns like in the case of Laravel for example, the "Chain of Responsibility" pattern. They don't come right out and say that, but after you study patterns a bit and look at how some of these features work, you may recognize them. You don't need to know any of this to build apps with these frameworks, but you do need to understand basic PHP oop, and interfaces, type hinting, annotations (and now in PHP 8, attributes which have basically replaced the need for annotations) inheritance etc. You MUST get comfortable with Composer. You MUST understand autoloading. You MUST understand how autoloading works with your own classes, and where to put those when you need them. It is possible to do full apps just using the models/controllers/twig templates in the places the symfony manual and tutorials tell you to put them, although this will often lead to lots of "not DRY" code and fat controllers. From a learning standpoint, that's somewhat natural, and nothing to worry about, but eventually you will probably see the problems and seek to remedy them by creating your own classes, which will then be used as services in your controller code. Last but not least, I highly recommend getting a handle on unit tests, and how to write and run them. Test coverage is another area where these frameworks are an amazing value because the developers have worked hard to provide unit tests for their code, so there's a high degree of built in quality. There are lots of frameworks out there, where people did their own take on a framework, and inevitably, they lack unit tests, documentation etc.. One last thing on Symfonycasts. Symfonycasts is a superb resource, started by the long time Symfony documentation lead, Ryan Weaver. The tech built into the tutorial system is fantastic. Full transcription, and code snippets built into everything, so you can alternate between reading or watching as you desire. It costs $25 a month, and if you simply want to learn Symfony in all its sophistication, it's highly worth it, as you can sit down and power through the material in directed fashion. There is a huge amount of material they have covered, but it can also be dense. With the proliferation of javascript UI/UX frameworks like React and Vue, people aren't building apps the same way anymore, and there are a lot more apps where the backend is a REST api, and the frontend is built using a javascript framework, and pulls the data from the backend as a REST client. Ryan has been adding a lot of content in these areas, reflecting the state of the art, and where the professional developer market has been going. I would suggest getting a handle on the traditional first, and then perhaps looking at some of these emerging techs that look to better bridge frontend/backend code. What I wouldn't recommend is buying a year subscription to save some bucks, and then finding out you didn't get enough use out of the subscription. Better to pay the higher monthly and make sure you are getting value out of it. Last but not least, I really like "Programming with GIO"'s youtube channel for foundational state of the art PHP and things like autoloading/composer/core OOP etc. It's free, and as good and probably better than a lot of paid courseware. Symfonycasts and Laracasts both have that material available (sometimes free) but in my opinion you want to spend your time on the stuff that is specific to symfony or laravel rather than the general stuff, should you subscribe to these services in order to advance your education in how to use them.
  6. gizmola

    Greetings!

    Symfony is typically used with the Doctrine Object Relational Mapper (ORM) library. The projects have long had a close collaboration. Having done projects with many different frameworks over the years, my preference would be to use Doctrine as an ORM vs. alternatives like Laravel's Eloquent. One reason for this, is that Eloquent is an implementation of the "Active Record" pattern, whereas, Doctrine is an implementation of the "Data Mapper" pattern. These are differing approaches to how ORMS are designed to work. You can find many active record ORM's in the PHP world, going back to frameworks like CakePHP. ORM's aren't quite as useful when using NoSQL databases like MongoDB. I did a project where there was a mix of data persistence between MySQL and MongoDB, and there was some utility in using Doctrine to interface with both, but many of the features of an ORM are specific to relational databases, and document databases are just an entirely different way of looking at things with different strengths and weaknesses. However, to conclude, Doctrine is a really great ORM to use with MySQL, and it is well integrated into Symfony, should you want to use it.
  7. HTTP based API's typically have a design. One popular way of creating an API is to utilize REST. I would encourage you to search for "REST API" and read some articles on it. It is not a cut and dry thing, but there are some important concepts to understand, and the best practice for applying HTTP methods GET/POST/PUT/DELETE as well as understanding the idea of idempotency in relation to resource location. Generally speaking, most api's are REST api's. It's also been a common best practice in most cases to utilize json as the format of data transfer (which is not dictated by REST or RESTfulness). Where OOP comes in, is that you want to think about and abstract the "entities" your application works with. As OOP is great for organizing data, I would highly recommend its use, and to think about the entities present in whatever application you are trying to create. There is a lot of overlap in these areas, with relational database design.
  8. To understand the code, you should debug what the $words array looks like. The reason the code currently works to sort by occurrence, is because the array looks like this: array ( 'red' => 7, 'mailbox' => 2, ) Barand gave you the answer, but you need to understand what the difference is between the two functions and when to use one vs the other.
  9. Your question is lacking in clarity. From what you've written, you have some sort of sale, and you want to offer a "button" that does "something" related to some other person potentially purchasing something on "the site". Who is this other person, and how are they to be identified? It sounds to me like what you are describing is like an affiliate or customer referral code. I'm not sure why they would need to click on a button, or what that button would do, unless it is just taking you to another page that includes a url parameter back to your site. Certainly, you can do something like this, but there isn't any magical code(z) floating around that make this work, unless this is functionality that is part of whatever e-comerce module you are using with your current system.
  10. I suggest using the model that Barand supplied. For the booking table, you create a unique index on screening_id, seat_id, and at that point you are protected from double booking for a screening. You can easily query for tickets sold for a screening, and can also determine what seats are available with a query like this: (Note, you constrain this query, knowing in advance the screen_id (I used 1 here) and the screening_id (used 35). In php these values would be fed into the query as parameters, but this is just an example: SELECT s.id, s.row, s.seat_no FROM seat s LEFT JOIN booking b ON b.seat_id = s.id AND b.screening_id = 35 WHERE s.screen_id = 1 AND b.id IS NULL
  11. I guess you don't understand that phpfreaks is a free site, with expert help provided by volunteers. Given the fact that everyone is donating their time and expertise to try and help people like yourself, the argument that you host a free site with source code you got from somewhere else for free, means you shouldn't ever have to learn anything (which can be learned in a few hours) will not get you much sympathy here.
  12. Make sure that none of your scripts have an end php tag in them. It is not needed and can often result in output being started accidentally. <?php // stuff ?> // <--- remove these from the end of all .php scripts.
  13. I have a note that the reverse engineered underlying code that will work with 8.x is this: SELECT CONCAT('*', UPPER(SHA1(UNHEX(SHA1('password')))));
  14. That is interesting to note. The main reason people used to use MyISAM tables intermixed in a database with InnoDB was to support fulltext indexing. Innodb didn't support fulltext search until version 5.6.4 which was released late in 2011.
  15. I don't know what functionality that is only in the MyISAM engine at this point. That is why Innodb is the default engine. With that said, the engine gets set for each table, and you can even alter the engine of an existing table, so it's possible to intermix them, but things like declarative referential integrity, transactions and row level locking only work with InnoDB tables.
  16. What the heck is this code? $customer["id"]; $customer["firstname"]; $customer["lastname"]; $customer["fullname"]; $customer["business_name"]; $customer["email"]; $customer["phone"]; $customer["mobile"]; $customer["address"]; $customer["city"]; $customer["state"]; $customer["zip"]; $customer["business_and_full_name"]; $customer["business_then_name"]; I have no idea why you would think that adding 5ms of sleep would help anything. Your PDO code should be using a prepared statement. Then you simply execute the statement in a loop, passing the data each time. It is well known that MySQL inserts are much faster if you do multiples: INSERT INTO Table (col1, col2) VALUES (?, ?), (?, ?), (?, ?).... This is one place where PDO doesn't have a built in solution, so you have to build your own, as Barand helpfully provided an example. It is possible to have limits on the size of a query, but would require a lot of data. Changing of that limit is dependent on what mysql library you are using, so I leave that to you to research. For example, if you are using mysqlnd, then a PDO runtime parameter changing that size is ignored. A good hybrid option would be to create a batch system where you load an array of the values inside the outer foreach, build the statement from that array, and prepare the statement and pass the array to the bind. However, the first stab I would take, would be to simply do a prepare and execute loop with a single transaction. $query = "INSERT INTO Customer (SyncroID, CompanyName) VALUES (?, ?)"; try { $pdo->beginTransaction(); $stmt = $pdo->prepare($query); foreach ($customers as $customer) { if (!empty($customer['business_name'])) { $stmt->execute([$customer['id'], $customer['business_name']]); } } $pdo->commit(); }catch (\Throwable $e){ $pdo->rollback(); throw $e; } Todo this type of thing effectively you need to make sure that the PDO connection has $conn->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ) and $conn->setAttribute( PDO::ERRMODE_EXCEPTION, true).
  17. I looked at the code, and it's fine. As others said, I'm not sure why it matters, if you are planning to use this as the basis for a project of your own, unless you are planning to try and pass the code off as something you wrote yourself.
  18. You really need to define what "I do have dedicated access to this whole server." If this statement is in anyway true, there is no reason for this to be so hard. I have no idea what you are talking about here, nor why this is a problem. Now, let's assume that you have 2 users you actually can connect to your server with and execute queries with a php program: db1user db2user While this is a needlessly inefficient method, you can do what you are requiring by writing a php program that: Makes 2 connections db1Connection db2Connection Selects data from db1.$g and fetches it all into an array foreach through the db1 result insert a db2.$g row There are many potential issues we can't address because you didn't even begin to describe the actual table structure of the $g table is (and why are you using a $ in the table name?), or how you will figure out what data from db1 you need. For example, if you have an auto increment primary key in the table(s), then you can't just take db1.$g.id = 300 and insert the whole row into db2.$g if for example, there is already a row with that id. What is the purpose of this exercise. If people know what you are trying to accomplish and why, there might be some other solution to solving the actual problem.
  19. The simple answer is that you de-couple the front end and the back end. The typical way to do this is to create an API for your backend code. Most frequently people choose a REST api. This is where the major frameworks (symfony, laravel, api platform) are extremely helpful and productive. There are some people who have a lot of negative things to say about Api platform, but it's purpose built for creating a backend api. From there you build your clients (javascript/native app or mobile framework app) against the api. This is really how large scale applications work.
  20. I'm not entirely sure what you are asking here, but PHP has arrays that are extremely flexible. An array element can contain a nested array, and you can also have multi-dimensional arrays. You can also mix arrays and class objects together, as in having a class, creating an object of that class and assigning it to an array, such that you have an array of objects. Either of these ideas could help you represent the data you have in your table. Arrays can be easily traversed using for loops or foreach.
  21. @Olumide Just a suggestion for you -- using var in javascript is frowned upon now when you have const and let.
  22. I don't see the issue. Can you clarify what you mean? When I look at the calendar on your site, as an example, Dec. 3, 2023 is a Sunday, which is correct.
  23. Using .env files is best practice, but probably not for the reasons you think. The main reason for those, is that previously people had a bad practice of actually putting credentials into files, and then they would get stored in source code repositories. What I would do with your project is to move all the files that can be directly called or referenced from "web space" ie. within or below the "web root" directory for the web server. What I'm going to describe to you is what pretty much all web projects do these days. So what I would do here, is create a public folder in your project. I would then move all the web directories (css, img, js) into it, as well as index.html, leaderboardtable.php and word-comparison.php into that directory. The .htaccess should also be in /public Note that these changes will break the application, and you will need corresponding changes, including regeneration of the autoload file with composer (assuming that is being used). The web configuration should then set the webroot to this projectname/public directory. At that point, you should notice what is no longer in web space: any project files the .env file dot files in the root the /vendor directory Depending on your web stack, there are additional tweaks you can make that might have some additional security benefits, if for example you are using fcgi/php-fpm or nginx with those etc. In those cases, you can utilize separate users for the php code and the web server, but at very least, moving anything out of "web space" means that you no longer have to try and knock down holes in a .htaccess, as users will only be able to directly reference the things you want them to, and there is no way they will be able to explore web space with the web browser, and potentially access a file that is used in your project.
  24. Consider the name of the feature. "Auto Loading" is a long standing feature of php that "automatically loads" a class simply by using it in your code. <?php $newObj = new MyClass(); By default, PHP has had a feature going all the way back to early versions, that would search particular directories you specified in the php.ini configuration file, looking to find a file that contains the definition for the file MyClass. Of course this had problems, including the fact that you could only have one "MyClass" defined. Any sophisticated PHP project, whether that be a forum, framework, cms etc., would need to keep its classes separate and distinct, and the potential for naming conflicts was significant. This is one of the reasons PHP added namespace support, so that a component library was free to name and structure its classes in whichever way was best for the developer, and still allow its classes to be used by other developers without conflict. Some of the leading framework and library project developers got together and formed FIG, in order to create standards documents, which they did for autoloaders in PSR-0 and then PSR-4. You should read those PSR's, or at least PSR-4 which is the current standard for how an autoloader should work, and how classes should be namespaced. At this point, because people should be using composer to manage the libraries and dependencies of their projects, and composer will generate the autoloading code, to include. If you follow the chain of code that is generated by composer, you'll see where it calls spl_autoload to register the custom autoloader code.
  25. Most discussion is in the PHP coding help, and at times the Client Side sub forums.
×
×
  • 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.