<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ucscode</title>
    <description>The latest articles on DEV Community by Ucscode (@ucscode).</description>
    <link>https://dev.to/ucscode</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F927609%2F11055634-0ed5-4d78-86ca-20cd3d228a75.png</url>
      <title>DEV Community: Ucscode</title>
      <link>https://dev.to/ucscode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ucscode"/>
    <language>en</language>
    <item>
      <title>Automate HTML Tables Generation in PHP with this Modern Library</title>
      <dc:creator>Ucscode</dc:creator>
      <pubDate>Sun, 02 Mar 2025 19:28:30 +0000</pubDate>
      <link>https://dev.to/ucscode/automate-html-tables-generation-in-php-with-this-modern-library-c9h</link>
      <guid>https://dev.to/ucscode/automate-html-tables-generation-in-php-with-this-modern-library-c9h</guid>
      <description>&lt;p&gt;Imagine writing a single line of code that will generate a fully functional table like the one below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5kccfclwzfr9rhgguxe3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5kccfclwzfr9rhgguxe3.png" alt=" " width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Interestingly, this is not based on random data but one that fully aligns with your project. Yes, a simple line of code can create a modular and customizable table from your database information.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Struggle With HTML Tables
&lt;/h2&gt;

&lt;p&gt;If you've ever worked with HTML tables in PHP, you know how tedious they can be. Manually writing out &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;tr&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;td&amp;gt;&lt;/code&gt; elements for dynamic content quickly becomes messy and unmanageable. Developers often resort to concatenating strings or using templating engines, but these approaches come with their own challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Error-prone&lt;/strong&gt;: A missing closing tag can break your entire layout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Difficult to maintain&lt;/strong&gt;: Making changes to table structure requires rewriting large chunks of code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limited flexibility&lt;/strong&gt;: Applying different styles, attributes, or handling special cases can get complicated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reusability&lt;/strong&gt;: Managing dynamic data across multiple tables can be cumbersome.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tables are one of the most common elements in web development. Whether it's an &lt;strong&gt;E-commerce product listing, admin user management, or a helpdesk ticket system&lt;/strong&gt;, generating tables is a repetitive task.&lt;/p&gt;




&lt;h2&gt;
  
  
  Introducing: The Ucscode Table Generator
&lt;/h2&gt;

&lt;p&gt;Wouldn’t it be great if generating tables in PHP were as simple as working with arrays or objects? That’s exactly what &lt;code&gt;Ucscode/table-generator&lt;/code&gt; offers—a structured, object-oriented approach to creating and managing HTML tables efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  🚀 Basic Usage: Creating a Simple Table
&lt;/h3&gt;

&lt;p&gt;Let’s start with a simple example. Suppose you want to generate a table displaying user data from an associative array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'John Doe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'john@example.com'&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Jane Doe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'jane@example.com'&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Ucscode Table Generator, you can generate a table effortlessly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Ucscode\HtmlComponent\TableGenerator\Adapter\AssocArrayAdapter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Ucscode\HtmlComponent\TableGenerator\TableGenerator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$adapter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AssocArrayAdapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$tableGenerator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TableGenerator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$adapter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$tableGenerator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🖥️ Output:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;table&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;ID&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Name&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Email&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;John Doe&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;john@example.com&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;Jane Doe&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;jane@example.com&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔍 Breaking It Down
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Adapters: Making Data Work&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;AssocArrayAdapter&lt;/code&gt; is just one of many adapters. An adapter is responsible for accepting a specific data type and converting it into a format that the &lt;code&gt;TableGenerator&lt;/code&gt; can process. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Working with an associative array?&lt;/strong&gt; Use &lt;code&gt;AssocArrayAdapter&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fetching data from MySQL?&lt;/strong&gt; Use &lt;code&gt;MysqliResultAdapter&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Want to process API responses?&lt;/strong&gt; You can create a custom adapter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;TableGenerator: Your Table Engine&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;TableGenerator&lt;/code&gt; takes the adapter and processes the extracted data into an HTML table. This method keeps data separate from presentation logic, improving clarity and maintainability.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Why This Approach Works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No messy HTML strings&lt;/strong&gt; – The library handles all the markup.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clearer structure&lt;/strong&gt; – Data remains separate from presentation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easier maintenance&lt;/strong&gt; – Updating the table structure is straightforward.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔥 Advanced Features
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Adapters for Different Data Sources&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;One powerful feature of this library is its ability to work with various data sources through &lt;strong&gt;Adapters&lt;/strong&gt;. For instance, if your data comes from an API, you can create a &lt;code&gt;CustomApiJsonAdapter&lt;/code&gt; to process the response effortlessly.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Customization: Enhancing Your Table&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;By default, the table is plain. But you can fully customize it with &lt;strong&gt;Middleware&lt;/strong&gt; to modify columns, apply styles, or add interactive elements.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Middleware: The Power of Modification&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Middleware allows you to transform table data dynamically without modifying the core logic.&lt;/p&gt;

&lt;h4&gt;
  
  
  📌 Example: Adding Checkboxes to Rows
&lt;/h4&gt;

&lt;p&gt;Checkboxes are essential for bulk actions. Instead of manually adding &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; elements, use &lt;strong&gt;CheckboxMiddleware&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Ucscode\HtmlComponent\HtmlTableGenerator\Middleware\CheckboxMiddleware&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$tableGenerator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;addMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CheckboxMiddleware&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This automatically inserts a checkbox into the first column of each row.&lt;/p&gt;




&lt;h2&gt;
  
  
  📌 Why Choose &lt;code&gt;Ucscode/table-generator&lt;/code&gt;?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight&lt;/strong&gt; – No unnecessary dependencies.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible API&lt;/strong&gt; – Works for both simple and complex use cases.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extensible&lt;/strong&gt; – Supports custom middlewares and adapters.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Beginner-Friendly&lt;/strong&gt; – Quick setup with minimal learning curve.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open Source&lt;/strong&gt; – Free to use, modify, and contribute!
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 Get Started Today!
&lt;/h2&gt;

&lt;p&gt;If you're tired of manually generating HTML tables in PHP, give &lt;code&gt;ucscode/table-generator&lt;/code&gt; a try! It's an elegant solution for creating tables in a structured, maintainable way.&lt;/p&gt;

&lt;p&gt;🔗 &lt;strong&gt;&lt;a href="https://tablegenerator.ucscode.com" rel="noopener noreferrer"&gt;Check out the full documentation&lt;/a&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;🔗 &lt;strong&gt;&lt;a href="https://github.com/ucscode/table-generator" rel="noopener noreferrer"&gt;Check out the repository on GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have feedback or feature suggestions? Drop a comment below! 👇&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>opensource</category>
      <category>php</category>
    </item>
    <item>
      <title>How To Handle Custom S/DQL Queries On Different Database Engine with DoctrineExpression</title>
      <dc:creator>Ucscode</dc:creator>
      <pubDate>Sun, 27 Oct 2024 03:40:46 +0000</pubDate>
      <link>https://dev.to/ucscode/how-to-handle-custom-sdql-queries-on-different-database-engine-with-doctrineexpression-2j64</link>
      <guid>https://dev.to/ucscode/how-to-handle-custom-sdql-queries-on-different-database-engine-with-doctrineexpression-2j64</guid>
      <description>&lt;p&gt;In the journey of building robust Symfony projects, there often comes a point where simple Entity Repository methods like &lt;code&gt;findBy()&lt;/code&gt; are no longer sufficient. For me, that point arrived, and I reached for the power of custom DQL queries to handle more complex data retrieval needs. At the time, I was using &lt;strong&gt;MySQL&lt;/strong&gt; as my default database. Everything worked perfectly until I containerized my project and decided to switch over to &lt;strong&gt;PostgreSQL&lt;/strong&gt; for performance and feature flexibility.&lt;/p&gt;

&lt;p&gt;But, oh no! My DQL queries immediately began throwing errors 😵‍💫. What went wrong? My custom DQL syntax was perfectly crafted for MySQL’s quirks and functions but was incompatible with PostgreSQL. The choice was now between two challenging paths:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 1&lt;/strong&gt;: Revert back to MySQL to keep things safe.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But what if I wanted to share the project with a developer who preferred PostgreSQL?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Option 2&lt;/strong&gt;: Rewrite my DQL to support PostgreSQL.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But, what if I needed to switch back to MySQL later? Or what if I used a tool that only supported MySQL?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Choosing between these wasn’t easy—both options could lock me into a single database environment, limiting flexibility in future tech choices. So, I decided to take a different approach and created a solution to dynamically handle database-specific queries in a clean, reusable way.&lt;/p&gt;




&lt;h3&gt;
  
  
  Introducing DoctrineExpression
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/ucscode/doctrine-expression" rel="noopener noreferrer"&gt;DoctrineExpression&lt;/a&gt; is a PHP library designed to enable cross-platform, database-agnostic DQL and SQL queries in Symfony or any project that utilizes doctrine. With DoctrineExpression, you can define custom syntax for each database platform (MySQL, PostgreSQL, SQLite, etc.), and it will select the correct expression based on the current database driver. It works like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Define Multiple Expressions&lt;/strong&gt;: Write different syntax for each database driver, specifying unique queries that match each platform’s functions and quirks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic Driver Detection&lt;/strong&gt;: DoctrineExpression checks the Doctrine platform in use, then automatically applies the correct syntax for MySQL, PostgreSQL, or any other supported database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Future-Proof Flexibility&lt;/strong&gt;: By allowing you to switch databases easily, DoctrineExpression future-proofs your code, ensuring that you can support multiple databases without extensive rewrites.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, with DoctrineExpression, I have the flexibility to use either MySQL or PostgreSQL (or even SQLite), keeping my code clean and maintainable. I can switch platforms based on project requirements, team preferences, or performance considerations without worrying about refactoring every custom query.&lt;/p&gt;

&lt;h3&gt;
  
  
  How DoctrineExpression Solves the Problem
&lt;/h3&gt;

&lt;p&gt;Let’s look at a simple example where we need to retrieve users who registered within the last 24 hours. This is often handled differently in MySQL and PostgreSQL.&lt;/p&gt;




&lt;h4&gt;
  
  
  Without DoctrineExpression
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;MySQL&lt;/strong&gt;: Uses &lt;code&gt;DATE_SUB(NOW(), INTERVAL 1 DAY)&lt;/code&gt; to find records within the last 24 hours.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL&lt;/strong&gt;: Uses &lt;code&gt;NOW() - INTERVAL '1 day'&lt;/code&gt; for the same query.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s how you might write these separately without DoctrineExpression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// MySQL Query&lt;/span&gt;
&lt;span class="nv"&gt;$mysqlQuery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$entityManager&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;createQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"SELECT u FROM App\Entity\User u WHERE u.registeredAt &amp;gt; DATE_SUB(NOW(), INTERVAL 1 DAY)"&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you were using PostgreSQL, you would write in this format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// PostgreSQL Query&lt;/span&gt;
&lt;span class="nv"&gt;$postgresQuery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$entityManager&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;createQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"SELECT u FROM App\Entity\User u WHERE u.registeredAt &amp;gt; NOW() - INTERVAL '1 day'"&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you switch databases, you'll need to modify this code, which is inconvenient and error-prone.&lt;/p&gt;




&lt;h4&gt;
  
  
  With DoctrineExpression
&lt;/h4&gt;

&lt;p&gt;With DoctrineExpression, you define both syntaxes and let the library handle the rest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Ucscode\DoctrineExpression\DoctrineExpression&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Ucscode\DoctrineExpression\DriverEnum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Create an expression instance with an EntityManager argument&lt;/span&gt;
&lt;span class="nv"&gt;$expression&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DoctrineExpression&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$entityManager&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Registration S/DQL for varying database&lt;/span&gt;
&lt;span class="nv"&gt;$expression&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;defineQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DriverEnum&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PDO_MYSQL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$entityManager&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$entityManager&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;createQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"SELECT u FROM App\Entity\User u WHERE u.registeredAt &amp;gt; DATE_SUB(NOW(), INTERVAL 1 DAY)"&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;defineQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DriverEnum&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PDO_PGSQL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$entityManager&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$entityManager&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;createQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"SELECT u FROM App\Entity\User u WHERE u.registeredAt &amp;gt; NOW() - INTERVAL '1 day'"&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Fet any of the defined query based on the active doctine driver being used&lt;/span&gt;
&lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$expression&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCompatibleResult&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;code&gt;DoctrineExpression&lt;/code&gt; checks the database platform in use and dynamically inserts the correct syntax for the current environment. It doesn't matter anymore you’re using MySQL or PostgreSQL, it will select the correct expression, saving you from having to modify your queries every time you switch platforms and also removes the boilerplate of using &lt;code&gt;if-else&lt;/code&gt; repeatedly&lt;/p&gt;

&lt;h3&gt;
  
  
  In Conclusion:
&lt;/h3&gt;

&lt;p&gt;DoctrineExpression saves time and effort by allowing you to use different databases without rewriting your queries. It’s particularly useful in containerized or multi-environment projects where you need to use custom syntax but database preferences may change depending on deployment needs or team familiarity. Give it a try, and let me know how it works for you!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ucscode/doctrine-expression" rel="noopener noreferrer"&gt;Check out DoctrineExpression on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>symfony</category>
      <category>doctrine</category>
      <category>postgressql</category>
      <category>php</category>
    </item>
    <item>
      <title>User Synthetics: A Modular Web Development Framework</title>
      <dc:creator>Ucscode</dc:creator>
      <pubDate>Sat, 17 Jun 2023 01:35:44 +0000</pubDate>
      <link>https://dev.to/ucscode/user-synthetics-a-modern-revolutionary-web-development-202g</link>
      <guid>https://dev.to/ucscode/user-synthetics-a-modern-revolutionary-web-development-202g</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;In today's fast-paced digital world, delivering exceptional user experiences has become paramount. As web developers, we constantly seek innovative tools and frameworks that empower us to create dynamic, efficient, and user-centric applications. In this article, I am excited to introduce you to User Synthetics, a cutting-edge lightweight PHP framework that is set to revolutionize web development. Before we proceed, let's look into a simple code:&lt;/p&gt;

&lt;h3&gt;
  
  
  Sample Code:
&lt;/h3&gt;

&lt;p&gt;To give you a taste of the power and simplicity of User Synthetics, let's take a look at a snippet of code that showcases its capabilities:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="n"&gt;uss&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;focus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Render the homepage template&lt;/span&gt;
    &lt;span class="nv"&gt;$content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;h1&amp;gt;Welcome to User Synthetics&amp;lt;/h1&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;p class="text-primary"&amp;gt;Create amazing &amp;amp;amp; responsive web applications with ease!&amp;lt;/p&amp;gt;'&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="n"&gt;uss&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we define a route for the "home" page and render the content in a fully featured environment containing bootstrap 5, bootbox, bs-icon and more. This is just a glimpse of the elegance and flexibility that User Synthetics offers.&lt;/p&gt;

&lt;p&gt;Interesting Factors to Explore:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Simplified Development Workflow: User Synthetics provides a streamlined development workflow with features like template building, event management, and JavaScript interaction. This empowers developers to focus on creating unique functionalities and delivering exceptional user experiences.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enhanced Performance and Efficiency: With optimized code structure and smart resource management, User Synthetics ensures lightning-fast application performance, resulting in reduced load times and improved user satisfaction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Flexible Templating System: User Synthetics offers a powerful templating system that allows developers to create visually stunning and responsive user interfaces. It supports dynamic content rendering, reusable components, and easy integration with JavaScript frameworks, making front-end design a breeze.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Seamless Integration with Third-Party Services: User Synthetics seamlessly integrates with various third-party services, enabling developers to leverage powerful functionalities like user authentication, payment gateways, and social media APIs. This saves time and effort, allowing developers to focus on core application logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Robust Security Measures: User Synthetics prioritizes security with built-in measures such as nonce handling, request URI management, and protection against common vulnerabilities. This ensures that your applications are secure and protected against potential threats.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To explore more about User Synthetics and join the vibrant community, visit the official website: &lt;a href="https://uss.ucscode.me" rel="noopener noreferrer"&gt;uss.ucscode.me&lt;/a&gt;. You can find comprehensive documentation, tutorials, live demo and code samples to get started.&lt;/p&gt;




&lt;p&gt;User Synthetics is poised to transform the web development landscape by providing developers with a powerful and intuitive framework. With its simplified workflow, enhanced performance, flexible templating, seamless integrations, and robust security measures, User Synthetics opens up endless possibilities for creating extraordinary web applications.&lt;/p&gt;

&lt;p&gt;Discover the world of User Synthetics and unlock your creative potential. Dive into the official documentation, explore the vibrant community, and start building exceptional web experiences today. Get ready to revolutionize the digital realm with User Synthetics!&lt;/p&gt;

&lt;p&gt;For documentation on how to work with user synthetics, visit the &lt;a href="https://uss.ucscode.me/docs" rel="noopener noreferrer"&gt;documentation page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's party
&lt;/h2&gt;

&lt;p&gt;I invite you to join the conversation and share your thoughts on User Synthetics. Are you excited about the potential of this modern web development tool? Do you have any questions or ideas about how it can be utilized effectively? Your input is valuable in shaping the future of User Synthetics and its applications. Let's spark a dialogue and explore the possibilities together. Feel free to leave a comment and engage with the community. Together, we can uncover new insights, inspire innovation, and empower each other in the world of web development.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>bootstrap</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
