<?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>Forem: Durgesh Sahani</title>
    <description>The latest articles on Forem by Durgesh Sahani (@durgeshsahani).</description>
    <link>https://forem.com/durgeshsahani</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%2F796894%2Fce9ee3e9-e0bc-4c99-b9f4-beb47fba3c91.jpeg</url>
      <title>Forem: Durgesh Sahani</title>
      <link>https://forem.com/durgeshsahani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/durgeshsahani"/>
    <language>en</language>
    <item>
      <title>Migration from Rackspace Server to Google Cloud Platform(GCP)</title>
      <dc:creator>Durgesh Sahani</dc:creator>
      <pubDate>Thu, 23 Mar 2023 06:49:18 +0000</pubDate>
      <link>https://forem.com/durgeshsahani/migration-from-rackspace-server-to-google-cloud-platformgcp-40ha</link>
      <guid>https://forem.com/durgeshsahani/migration-from-rackspace-server-to-google-cloud-platformgcp-40ha</guid>
      <description>&lt;p&gt;Migrating from a &lt;code&gt;Rackspace&lt;/code&gt; server to the &lt;code&gt;Google Cloud Platform (GCP)&lt;/code&gt; can be a daunting task, but it can also bring many benefits such as scalability, security, and cost savings. In this blog, we will walk through the process of migrating from a &lt;code&gt;Rackspace&lt;/code&gt; server to &lt;code&gt;GCP&lt;/code&gt; and discuss some of the key considerations and best practices to keep in mind.&lt;/p&gt;

&lt;p&gt;Before beginning the migration process, it is important to plan and prepare for the move. This includes identifying which resources and data need to be migrated, as well as determining the most efficient and cost-effective way to move them.&lt;/p&gt;

&lt;h2&gt;
  
  
  RackSpace Server
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Server&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hardwares&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;8GB RAM, 100GB SSD&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Softwares&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Debian 10, Apache 2.4, PHP 7.4&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;MySQL 5.7&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resources&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Images, PDF’s, Excel, etc&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DNS&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Domain, Subdomain, Other Records like CNAME, A, TXT, MX, etc&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Additional Dependency’s&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Additional Softwares like: RabbitMQ, Elasticsearch, CRONS, etc&lt;/li&gt;
&lt;li&gt;Check Enabled PORTS like: 80, 443, 21, etc&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the most important considerations for migration is the data. It is important to take a full backup of all data on the &lt;code&gt;Rackspace&lt;/code&gt; server, including databases, files, and configurations. This backup should be tested to ensure that it can be restored successfully.&lt;/p&gt;

&lt;p&gt;Next, it is important to choose the appropriate &lt;code&gt;GCP&lt;/code&gt; services for your workloads. GCP offers a wide range of services, including compute, storage, networking, and databases, that can be used to run your applications and store your data. Depending on the specific requirements of your workloads, you may want to use services like Google Compute Engine, Google Kubernetes Engine, Google Cloud Storage, or Cloud SQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Replica Of RackSpace Server to Google Cloud Platform(GCP)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Server – &lt;code&gt;Google Compute Engine&lt;/code&gt;&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hardwares&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;8GB RAM, 100GB SSD&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Softwares&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Debian 10, Apache 2.4, PHP 7.4&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database – &lt;code&gt;Cloud SQL&lt;/code&gt;&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;MySQL 5.7&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resources – &lt;code&gt;Cloud Storage&lt;/code&gt;&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Images, PDF’s, Excel, etc&lt;/li&gt;
&lt;li&gt;Created/Configured CDN with Loadbalancer to access these resources&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DNS – &lt;code&gt;Cloud DNS&lt;/code&gt;&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Domain, Subdomain, Other Records like CNAME, A, TXT, MX, etc&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Additional Dependency’s&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Additional Softwares like: RabbitMQ, Elasticsearch, CRONS, etc&lt;/li&gt;
&lt;li&gt;Enabled PORTS like: 80, 443, 21, etc&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Along with server migration we moved all resources to &lt;code&gt;Google Cloud Bucket&lt;/code&gt; and created &lt;code&gt;CDN&lt;/code&gt; to access them. We have also updated the code to access file from &lt;code&gt;CDN&lt;/code&gt;, upload files to Cloud bucket, Download file from Cloud bucket. By following these steps, we have optimise our server resources and improve your website’s overall performance.&lt;/p&gt;

&lt;p&gt;To do this you have to make sure you have given right permission to bucket so files can be accessible, also handle the &lt;code&gt;CORS&lt;/code&gt; issue by making some configuration changes in cloud bucket. Another issue we faced was resizing images as first we have to download it then resize and finally upload it again.&lt;/p&gt;

&lt;p&gt;Once you have chosen the appropriate &lt;code&gt;GCP&lt;/code&gt; services, you can begin migrating your data and resources. There are several different methods for migrating data and resources, including manual migration, using migration tools, or using a hybrid approach. The method you choose will depend on the size and complexity of your workloads, as well as the resources and expertise available to you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Google Cloud Platform offers a range of powerful tools like gsutil that can greatly simplify and automate many tasks related to managing and using cloud services.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Gsutil&lt;/code&gt; is a command-line tool that allows you to interact with Cloud Storage from the command line. With &lt;code&gt;gsutil&lt;/code&gt;, you can also automate tasks such as backups, synchronizing data between local and cloud storage, and running batch jobs. This can save you time and effort, and help you to more efficiently manage your cloud resources.&lt;/p&gt;

&lt;p&gt;We configured it to &lt;code&gt;Rackspace&lt;/code&gt; server to transfer all the resources(Images, PDF’s, Excel files, etc), exported mysql databases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Another helpful tool we used was SCREEN.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;screen&lt;/code&gt; tool is a terminal multiplexer that allows you to create multiple “virtual” terminals within a single terminal window. This can be useful for a variety of tasks, including running multiple commands simultaneously, detaching from a terminal session while leaving the commands running in the background, and transferring larger files in the background.&lt;/p&gt;

&lt;p&gt;To transfer larger files in the background using &lt;code&gt;screen&lt;/code&gt;, you can start a &lt;code&gt;screen&lt;/code&gt; session and then initiate the file transfer using a command-line tool such as &lt;code&gt;rsync&lt;/code&gt; or &lt;code&gt;scp&lt;/code&gt; In our case we used &lt;code&gt;gsutil&lt;/code&gt;. Once the transfer has started, you can detach from the &lt;code&gt;screen&lt;/code&gt; session using the key combination &lt;code&gt;Ctrl+a d&lt;/code&gt;. This will leave the transfer running in the background and allow you to continue using the terminal for other tasks.&lt;/p&gt;

&lt;p&gt;To reattach to the &lt;code&gt;screen&lt;/code&gt; session and check the progress of the transfer, you can use the command &lt;code&gt;screen -r&lt;/code&gt;. This will restore the &lt;code&gt;screen&lt;/code&gt; session and allow you to view the output of the running commands.&lt;/p&gt;

&lt;p&gt;It’s also important to keep in mind the security and compliance requirements during this migration process. GCP provides various security and compliance features such as encryption, firewalls, and identity and access management to keep your data and resources secure.&lt;/p&gt;

&lt;p&gt;Once the migration is complete, it is important to thoroughly test your applications and services to ensure that they are working as expected. This includes monitoring the performance of your workloads, troubleshooting any issues that may arise, and making any necessary adjustments to your GCP configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some major issues we faces post migrations are:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We experience slowness issue on production server. Root cause was cache was disabled in Apache, innodb buffer size, query cache mode was disabled in MySQL.&lt;/li&gt;
&lt;li&gt;Apache configuration updates were missing like: &lt;code&gt;http_module&lt;/code&gt;, &lt;code&gt;rewrite_module&lt;/code&gt;, &lt;code&gt;headers_module&lt;/code&gt;, &lt;code&gt;ssl_module&lt;/code&gt;. &lt;code&gt;Execute this&lt;/code&gt; &lt;strong&gt;apachectl -M&lt;/strong&gt; command to get all the list of modules.&lt;/li&gt;
&lt;li&gt;Missed to update MySQL modes like: &lt;code&gt;NO_ENGINE_SUBSTITUTION&lt;/code&gt;, &lt;code&gt;innodb_buffer_pool_size&lt;/code&gt;, &lt;code&gt;query_cache_size&lt;/code&gt;, etc
Directory permissions were missing to create folders, upload files, etc.&lt;/li&gt;
&lt;li&gt;Email with attachments were missing the file as file were on bucket not on server anymore.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In conclusion, migrating from a &lt;code&gt;Rackspace server&lt;/code&gt; to &lt;code&gt;GCP&lt;/code&gt; can be a complex process, but it can bring many benefits such as scalability, security, and cost savings. It’s important to plan and prepare for the move, choose the appropriate GCP services, and keep in mind the security and compliance requirements during the migration process. It’s also important to thoroughly test your applications and services after the migration to ensure that they are working as expected.&lt;/p&gt;

&lt;p&gt;Thanks for taking the time to read this. If you have any further questions or need more information, please don't hesitate to ask.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reach Out
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dwebworks.in/"&gt;https://dwebworks.in/&lt;/a&gt;&lt;br&gt;
&lt;a href="mailto:dwebworks.in@gmail.com"&gt;dwebworks.in@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>cloudmigratio</category>
      <category>gcp</category>
      <category>googlecloud</category>
    </item>
    <item>
      <title>Upgrading from PHP 5.6 to PHP 7.4</title>
      <dc:creator>Durgesh Sahani</dc:creator>
      <pubDate>Tue, 21 Mar 2023 05:17:16 +0000</pubDate>
      <link>https://forem.com/durgeshsahani/upgrading-from-php-56-to-php-74-5dg7</link>
      <guid>https://forem.com/durgeshsahani/upgrading-from-php-56-to-php-74-5dg7</guid>
      <description>&lt;p&gt;Upgrading from PHP 5.6 to 7.4 can be a daunting task, but it is important to do so in order to take advantage of the many new features and performance improvements in the latest version of the language.&lt;/p&gt;

&lt;p&gt;Before starting the upgrade process, it is important to thoroughly test your application on a development or staging server to ensure that it is compatible with PHP 7.4. This will allow you to identify and fix any issues before deploying to a production environment.&lt;/p&gt;

&lt;p&gt;One of the biggest changes in PHP 7.4 is the deprecation of several functions and features that were previously available in PHP 5.6. For example, the create_function() function has been removed, and the mysql_* functions have been deprecated in favor of the mysqli_* or PDO_* functions.&lt;/p&gt;

&lt;p&gt;Additionally, certain syntax changes have been made in PHP 7.4. For example, the list() function now requires parentheses, and the callable type has been replaced with Closure.&lt;/p&gt;

&lt;p&gt;It is also important to note that PHP 7.4 has removed support for several older versions of popular extensions, such as mcrypt, and openssl. It’s important that you update these to the latest version of these extensions to be compatible with PHP 7.4.&lt;/p&gt;

&lt;p&gt;Once all compatibility issues have been addressed, the actual process of upgrading can begin. This typically involves updating the PHP version on the server and updating any necessary extensions.&lt;/p&gt;

&lt;p&gt;It’s also important to note that you should also update any dependencies and libraries that are used by your application. This includes updating any frameworks or libraries that are used by your application.&lt;/p&gt;

&lt;p&gt;Once the upgrade is complete, it is important to thoroughly test your application again to ensure that everything is working as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some major issues we faces post migrations are:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;We migrated from mysql_* with PDO&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We implemented PDO in such a way that it can also handle read-replica in future &lt;strong&gt;Db::getPdoRead&lt;/strong&gt;, &lt;strong&gt;Db::getPdoWrite&lt;/strong&gt;, but there was a challenge in the beginning, team was making mistake to using it in right object which actually created problem for form data not being stored in database, &lt;/li&gt;
&lt;li&gt;Converting bigger &lt;strong&gt;SELECT&lt;/strong&gt; with &lt;strong&gt;multiple tables joins&lt;/strong&gt; and &lt;strong&gt;multiple parameters&lt;/strong&gt; query to PDO &lt;/li&gt;
&lt;li&gt;Another issue we faced was after conversion sometime response got swapped &lt;strong&gt;index_value&lt;/strong&gt; to &lt;strong&gt;key_value&lt;/strong&gt; or voice-versa&lt;/li&gt;
&lt;li&gt;Other issue related to same we faced was we have to &lt;strong&gt;fetchAll()&lt;/strong&gt; record but we use &lt;strong&gt;fetch()&lt;/strong&gt; or voice-versa we created data mismatch&lt;/li&gt;
&lt;li&gt;We decided to replace &lt;strong&gt;mysql_real_escape_string()&lt;/strong&gt; with &lt;strong&gt;addslashes()&lt;/strong&gt; which created another issue on production while saving html contents.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Merging branches, lots of conflicts, if someone forgot to rebase or worked for weeks without taking updates.&lt;/strong&gt;&lt;/em&gt; &lt;strong&gt;It took week to resolve conflicts.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In summary, upgrading from PHP 5.6 to 7.4 can be a complex process, but it is important to do so in order to take advantage of the many new features and performance improvements in the latest version of the language. It’s important to thoroughly test your application before and after the upgrade, and to update any necessary dependencies and libraries.&lt;/p&gt;

&lt;p&gt;Thanks for taking the time to read this. If you have any further questions or need more information, please don't hesitate to ask.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reach Out
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dwebworks.in/"&gt;https://dwebworks.in/&lt;/a&gt;&lt;br&gt;
&lt;a href="mailto:dwebworks.in@gmail.com"&gt;dwebworks.in@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>upgrade</category>
      <category>pdo</category>
    </item>
    <item>
      <title>Unlocking the Power of Offshore Development Teams: How to Build a Successful Remote Team in India</title>
      <dc:creator>Durgesh Sahani</dc:creator>
      <pubDate>Thu, 23 Feb 2023 05:13:04 +0000</pubDate>
      <link>https://forem.com/durgeshsahani/unlocking-the-power-of-offshore-development-teams-how-to-build-a-successful-remote-team-in-india-48ah</link>
      <guid>https://forem.com/durgeshsahani/unlocking-the-power-of-offshore-development-teams-how-to-build-a-successful-remote-team-in-india-48ah</guid>
      <description>&lt;p&gt;As the world becomes more interconnected, businesses are expanding their reach beyond borders to tap into new markets and take advantage of cost-effective solutions. One such solution is offshore development teams, which have become increasingly popular among companies looking to streamline their operations and reduce costs. Offshore development teams provide access to skilled professionals at a fraction of the cost of hiring in-house staff, and they offer a range of benefits that can help businesses achieve their long-term goals. In this blog, we'll explore the advantages of offshore development teams and why they're a smart choice for US/UK-based companies looking to stay ahead of the competition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why offshore team is better options than hiring contractors, freelancers?
&lt;/h2&gt;

&lt;p&gt;Offshore teams offer several advantages over hiring contractors or freelancers for software development. &lt;br&gt;
Firstly, offshore teams are generally more reliable and consistent than hiring individual contractors or freelancers. Offshore teams are often composed of multiple team members, which means that there is more accountability and less reliance on any one individual. This can help ensure that deadlines are met, quality is consistent, and work is completed on time.&lt;/p&gt;

&lt;p&gt;Secondly, offshore teams typically offer a broader range of skills and expertise than individual contractors or freelancers. An offshore team is often composed of multiple developers with different areas of expertise, such as front-end development, back-end development, database management, and more. This can help ensure that all aspects of a project are covered and that there are no gaps in knowledge or skill.&lt;/p&gt;

&lt;p&gt;Thirdly, offshore teams are often more cost-effective than hiring contractors or freelancers. Offshore teams are typically based in countries with lower labor costs, which means that the cost of hiring a team of developers can be significantly lower than the cost of hiring individual contractors or freelancers.&lt;br&gt;
Finally, offshore teams are often able to provide better project management and support than individual contractors or freelancers. Offshore teams typically have project managers and other support staff who can help ensure that the project runs smoothly and that any issues or challenges are addressed promptly.&lt;/p&gt;

&lt;p&gt;Overall, offshore teams can offer a number of advantages over hiring contractors or freelancers for software development, including reliability, expertise, cost-effectiveness, and project management and support.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now lets talk about Opportunities, Challenges, Solutions and Long-term goals
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Opportunities:&lt;/strong&gt;&lt;br&gt;
Despite the challenges, offshore development teams in India offer several opportunities for US/UK companies. One of the biggest opportunities is cost savings. Offshore development teams in India can offer up to 50-70% cost savings compared to in-house teams. India's highly skilled workforce and large pool of talent offer a wide range of expertise and skills for US/UK companies to tap into. This can help companies to access a wider talent pool, improve productivity and reduce time to market.&lt;br&gt;
&lt;strong&gt;Challenges:&lt;/strong&gt;&lt;br&gt;
However, setting up an offshore development team in India is not without its challenges. One of the biggest challenges is the cultural and language barrier. It is important for US/UK companies to understand the cultural differences and work towards bridging the gap. Language is another barrier that can affect communication and productivity. Finding the right talent and managing them remotely can also be a challenge.&lt;br&gt;
&lt;strong&gt;Solutions:&lt;/strong&gt;&lt;br&gt;
To overcome the challenges and make the most of the opportunities, US/UK companies need to adopt certain strategies. One of the most important strategies is to partner with a reliable and experienced offshore development team provider in India. This can help companies to overcome the cultural and language barriers, as well as ensure that they have access to the right talent. Building a strong and collaborative relationship with the offshore team is also crucial for success.&lt;br&gt;
&lt;strong&gt;Long-term goals:&lt;/strong&gt;&lt;br&gt;
Offshore development teams in India can offer several long-term benefits for US/UK companies. By leveraging India's highly skilled workforce and cost advantages, companies can focus on innovation, growth, and expanding their global reach. Offshore development teams can also offer a flexible and scalable solution that can adapt to the changing needs of the company. This can help companies to stay competitive and agile in the rapidly evolving business landscape.&lt;br&gt;
In conclusion, offshore development teams in India offer several benefits and opportunities for US/UK companies. However, it is important to understand the challenges and adopt the right strategies to make the most of the offshore team. With the right partner, US/UK companies can build a successful and long-lasting offshore development team in India.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we are helping company’s to scale?
&lt;/h2&gt;

&lt;p&gt;As a seasoned software engineer with over 10 years of experience in the industry, I have seen the immense value that offshore teams can bring to a company. Many businesses in the US and UK are facing the challenge of finding skilled developers who are not only affordable but also capable of delivering high-quality work.&lt;br&gt;
That's where we come in - our company, based in India, specializes in building offshore teams that are tailor-made to meet the unique needs of our clients. We understand that every business is different, and we work closely with our clients to create teams that are perfectly suited to their specific requirements.&lt;br&gt;
One of the biggest advantages of working with an offshore team is the cost savings that come with it. With salaries and expenses in India being significantly lower than those in the US or UK, companies can save up to 50-70% on their development costs without sacrificing quality or reliability.&lt;br&gt;
But cost savings are just the beginning - offshore teams also offer a range of other benefits that can help companies to achieve their long-term goals. For example, by tapping into a global talent pool, businesses can access a wider range of skills and experience than they might find locally. This can lead to more innovative solutions, better products, and a stronger competitive edge.&lt;br&gt;
Of course, there are also challenges that come with building an offshore team, such as language and cultural barriers, time zone differences, and communication issues. But these challenges can be overcome with the right approach and the right partner. Our team is experienced in working with clients from around the world, and we have developed processes and tools to ensure seamless collaboration and communication across borders.&lt;/p&gt;

&lt;p&gt;In conclusion, offshore teams offer a compelling solution for businesses that are looking to stay competitive in a rapidly changing marketplace. By working with a company like ours, US and UK companies can access a pool of talented developers at a fraction of the cost, without sacrificing quality or reliability. So why not take advantage of this opportunity and start building your offshore team today?&lt;/p&gt;

&lt;p&gt;Thanks for taking the time to read this. If you have any further questions or need more information, please don't hesitate to ask.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reach Out
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dwebworks.in/"&gt;https://dwebworks.in/&lt;/a&gt;&lt;br&gt;
&lt;a href="mailto:dwebworks.in@gmail.com"&gt;dwebworks.in@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>offshoreteam</category>
      <category>outsourcing</category>
      <category>remoteteam</category>
      <category>offshoredevelopment</category>
    </item>
    <item>
      <title>React CRUD operations using PHP API and MySQL</title>
      <dc:creator>Durgesh Sahani</dc:creator>
      <pubDate>Tue, 18 Jan 2022 13:38:34 +0000</pubDate>
      <link>https://forem.com/durgeshsahani/react-crud-operations-using-php-api-and-mysql-13da</link>
      <guid>https://forem.com/durgeshsahani/react-crud-operations-using-php-api-and-mysql-13da</guid>
      <description>&lt;h2&gt;
  
  
  What we are going to learn?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ReactJs introduction, Create React APP, NodeJs NPM and Homebrew installations&lt;/li&gt;
&lt;li&gt;Create Link and Handle Routing in React | react-router-dom package installation&lt;/li&gt;
&lt;li&gt;Create database in PHPMyAdmin and design form in React Component&lt;/li&gt;
&lt;li&gt;Create PHP API and consume using axios | handle CORS issue on localhost&lt;/li&gt;
&lt;li&gt;Connect MySQL database using PDO | Access React form data and Save in Database&lt;/li&gt;
&lt;li&gt;Create GET PHP API and consume in React using axios | List in react table component&lt;/li&gt;
&lt;li&gt;Load user details for edit form and create PHP PUT API to update user data&lt;/li&gt;
&lt;li&gt;Create DELETE PHP API, consume it using axios and delete user from database&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is ReactJs?
&lt;/h2&gt;

&lt;p&gt;React is a free and open-source front-end JavaScript library for building user interfaces based on UI components. It is maintained by Meta and a community of individual developers and companies. React can be used as a base in the development of single-page or mobile applications. Here is the official website of ReactJs &lt;a href="https://reactjs.org/"&gt;https://reactjs.org/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To create react app you’ll need to have Node &amp;gt;= 14.0.0 and npm &amp;gt;= 5.6 on your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is NodeJs and NPM?
&lt;/h2&gt;

&lt;p&gt;Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. You can download from official NodeJs website: &lt;a href="https://nodejs.org/en/"&gt;https://nodejs.org/en/&lt;/a&gt;. NPM will get install along with NodeJs. NPM is the default package manager for the JavaScript runtime environment NodeJs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Homebrew?
&lt;/h2&gt;

&lt;p&gt;For mac you can also use Homebrew to install it on your machine. Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s operating system, macOS, as well as Linux. The name is intended to suggest the idea of building software on the Mac depending on the user’s taste. here is the official website &lt;a href="https://brew.sh/"&gt;https://brew.sh/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Homebrew&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install NodeJs&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;brew install nodejs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create ReactJS APP&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;npx create-react-app react-crud&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;npx is not a typo — it’s a package runner tool that comes with npm 5.2+.&lt;/p&gt;

&lt;p&gt;Create React App doesn’t handle backend logic or databases; it just creates a frontend build pipeline, so you can use it with any backend you want. Under the hood, it uses Babel and webpack, but you don’t need to know anything about them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run react app&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd react-crud
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now visit to following link you should be able to see ReactApp running:&lt;br&gt;
&lt;code&gt;http://localhost:3000/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To create RestFull API, we’ll be needing PHP, MYSQL and Apache. You are free to install each software separately and configure them or use stacked app. In my case I’m going to use MAMP(Mac Apache MySQL PHP) which is design for mac and comes with all required softwares&lt;/p&gt;
&lt;h2&gt;
  
  
  What is PHP?
&lt;/h2&gt;

&lt;p&gt;PHP is a open-source general-purpose server side scripting language that is especially suited to web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1994. The PHP reference implementation is now produced by The PHP Group.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is MySQL?
&lt;/h2&gt;

&lt;p&gt;MySQL is an open-source relational database management system. Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Apache?
&lt;/h2&gt;

&lt;p&gt;The Apache HTTP Server is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.&lt;/p&gt;
&lt;h2&gt;
  
  
  Stacked Application
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;WAMP for Windows&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.wampserver.com/en/"&gt;https://www.wampserver.com/en/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;LAMP for Linux&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://bitnami.com/stack/lamp/installer"&gt;https://bitnami.com/stack/lamp/installer&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;MAMP for Mac&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.mamp.info/en/mac/"&gt;https://www.mamp.info/en/mac/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;XAMPP: Open Source, Cross-platform&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.apachefriends.org/index.html"&gt;https://www.apachefriends.org/index.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Awesome now we are all set to start. Open you project to your favourite code editor in my case I’m using Visual Studio Code.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create Link and Handle Routing in React | react-router-dom package installation
&lt;/h2&gt;

&lt;p&gt;Create new directory components under your src/ directory and create 3 new components which we’ll update shortly:&lt;br&gt;
&lt;strong&gt;src/components/ListUser.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function ListUser() {
  return (
      &amp;lt;h1&amp;gt;List Users&amp;lt;/h1&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;src/components/CreateUser.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function CreateUser() {
  return (
      &amp;lt;h1&amp;gt;Create User&amp;lt;/h1&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;src/components/UpdateUser.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function UpdateUser() {
  return (
      &amp;lt;h1&amp;gt;Update User&amp;lt;/h1&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now let’s Install react router for creating link and configuring routes&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;npm install react-router-dom&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update App.js for handling routing&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {BrowserRouter, Routes, Route, Link} from 'react-router-dom';
import './App.css';
import CreateUser from './components/CreateUser';
import EditUser from './components/EditUser';
import ListUser from './components/ListUser';
function App() {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h5&amp;gt;React CRUD operations using PHP API and MySQL&amp;lt;/h5&amp;gt;
      &amp;lt;BrowserRouter&amp;gt;
        &amp;lt;nav&amp;gt;
          &amp;lt;ul&amp;gt;
            &amp;lt;li&amp;gt;
              &amp;lt;Link to="/"&amp;gt;List Users&amp;lt;/Link&amp;gt;
            &amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;
              &amp;lt;Link to="user/create"&amp;gt;Create User&amp;lt;/Link&amp;gt;
            &amp;lt;/li&amp;gt;
          &amp;lt;/ul&amp;gt;
        &amp;lt;/nav&amp;gt;
        &amp;lt;Routes&amp;gt;
          &amp;lt;Route index element={&amp;lt;ListUser /&amp;gt;} /&amp;gt;
          &amp;lt;Route path="user/create" element={&amp;lt;CreateUser /&amp;gt;} /&amp;gt;
          &amp;lt;Route path="user/:id/edit" element={&amp;lt;EditUser /&amp;gt;} /&amp;gt;
        &amp;lt;/Routes&amp;gt;
      &amp;lt;/BrowserRouter&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create database in PHPMyAdmin and design form in React Component
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;CREATE DTAABASE react_crud;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE `react_crud`.`users` 
(
`id` int NOT NULL auto_increment,
`name` varchar(50),
`email` varchar(60),
`mobile` bigint(10),
`created_at` timestamp,
`updated_at` timestamp, PRIMARY KEY (id)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Update src/components/CreateUser.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";
export default function ListUser() {
    const [inputs, setInputs] = useState([]);
    const handleChange = (event) =&amp;gt; {
        const name = event.target.name;
        const value = event.target.value;
        setInputs(values =&amp;gt; ({...values, [name]: value}));
    }
    const handleSubmit = (event) =&amp;gt; {
        event.preventDefault();
        console.log(inputs);
    }
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;h1&amp;gt;Create user&amp;lt;/h1&amp;gt;
            &amp;lt;form onSubmit={handleSubmit}&amp;gt;
                &amp;lt;table cellSpacing="10"&amp;gt;
                    &amp;lt;tbody&amp;gt;
                        &amp;lt;tr&amp;gt;
                            &amp;lt;th&amp;gt;
                                &amp;lt;label&amp;gt;Name: &amp;lt;/label&amp;gt;
                            &amp;lt;/th&amp;gt;
                            &amp;lt;td&amp;gt;
                                &amp;lt;input type="text" name="name" onChange={handleChange} /&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                        &amp;lt;tr&amp;gt;
                            &amp;lt;th&amp;gt;
                                &amp;lt;label&amp;gt;Email: &amp;lt;/label&amp;gt;
                            &amp;lt;/th&amp;gt;
                            &amp;lt;td&amp;gt; 
                                &amp;lt;input type="text" name="email" onChange={handleChange} /&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                        &amp;lt;tr&amp;gt;
                            &amp;lt;th&amp;gt;
                                &amp;lt;label&amp;gt;Mobile: &amp;lt;/label&amp;gt;
                            &amp;lt;/th&amp;gt;
                            &amp;lt;td&amp;gt;
                                &amp;lt;input type="text" name="mobile" onChange={handleChange} /&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                        &amp;lt;tr&amp;gt;
                            &amp;lt;td colSpan="2" align ="right"&amp;gt;
                                &amp;lt;button&amp;gt;Save&amp;lt;/button&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                    &amp;lt;/tbody&amp;gt;
                &amp;lt;/table&amp;gt;
            &amp;lt;/form&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create PHP API and consume using axios | handle CORS issue on localhost
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Install axios for making API calls from ReactJs&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;npm install axios&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now update your src/components/CreateUser.js file again for making POST API call&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from "axios";
const handleSubmit = (event) =&amp;gt; {
    event.preventDefault();
    axios.post('http://localhost:8888/api/user/save', inputs).then(function(response){
        console.log(response.data);
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create PHP file for writing API and name it index.php&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
    header('Access-Control-Allow-Origin: *');
    header("Access-Control-Allow-Headers: *");
    echo "Testing";
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice at the top we have added headers to solved CORS issue.&lt;br&gt;
Also, Let’s create .htaccess file to handle pretty URLs like PHP lumen framework, and add following line inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hoola, Finally our API file is ready.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect MySQL database using PDO | Access React form data and Save in Database
&lt;/h2&gt;

&lt;p&gt;Now, Let’s create a database connect file and name it DbConnect.php and add following code snippet inside. Update credentials as per yours and it will connect to your database using PDO(PHP Data Object).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
    /**
    * Database Connection
    */
    class DbConnect {
        private $server = 'localhost';
        private $dbname = 'react_crud';
        private $user = 'root';
        private $pass = '';
        public function connect() {
            try {
                $conn = new PDO('mysql:host=' .$this-&amp;gt;server .';dbname=' . $this-&amp;gt;dbname, $this-&amp;gt;user, $this-&amp;gt;pass);
                $conn-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                return $conn;
            } catch (\Exception $e) {
                echo "Database Error: " . $e-&amp;gt;getMessage();
            }
        }

    }
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create POST API&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;include("DbConnect.php");
    $conn = new DbConnect();
    $db = $conn-&amp;gt;connect();
    $method = $_SERVER['REQUEST_METHOD'];
    switch($method) {
        case 'POST':
            $user = json_decode(file_get_contents('php://input'));
            $sql = "INSERT INTO users(id, name, email, mobile, created_at) values(null, :name, :email, :mobile, :created_at)";
            $stmt = $db-&amp;gt;prepare($sql);
            $date = date('Y-m-d');
            $stmt-&amp;gt;bindParam(':name', $user-&amp;gt;name);
            $stmt-&amp;gt;bindParam(':email', $user-&amp;gt;email);
            $stmt-&amp;gt;bindParam(':mobile', $user-&amp;gt;mobile);
            $stmt-&amp;gt;bindParam(':created_at', $date);
            if($stmt-&amp;gt;execute()) {
                $data = ['status' =&amp;gt; 1, 'message' =&amp;gt; "Record successfully created"];
            } else {
                $data = ['status' =&amp;gt; 0, 'message' =&amp;gt; "Failed to create record."];
            }
            echo json_encode($data);
            break;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Reference database connection class file and connect to MySQL Database
include("DbConnect.php");
$conn = new DbConnect();
$db = $conn-&amp;gt;connect();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Give you Method used to hit API
$method = $_SERVER['REQUEST_METHOD'];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Read the POST JSON data and convert it into PHP Object
$user = json_decode(file_get_contents('php://input'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create GET PHP API and consume in React using axios | List in react table component
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Update src/components/ListUser.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from "axios"
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
export default function ListUser() {
    const [users, setUsers] = useState([]);
    useEffect(() =&amp;gt; {
        getUsers();
    }, []);
    function getUsers() {
        axios.get('http://localhost:8888/api/users/').then(function(response) {
            console.log(response.data);
            setUsers(response.data);
        });
    }
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;h1&amp;gt;List Users&amp;lt;/h1&amp;gt;
            &amp;lt;table&amp;gt;
                &amp;lt;thead&amp;gt;
                    &amp;lt;tr&amp;gt;
                        &amp;lt;th&amp;gt;#&amp;lt;/th&amp;gt;
                        &amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;
                        &amp;lt;th&amp;gt;Email&amp;lt;/th&amp;gt;
                        &amp;lt;th&amp;gt;Mobile&amp;lt;/th&amp;gt;
                        &amp;lt;th&amp;gt;Actions&amp;lt;/th&amp;gt;
                    &amp;lt;/tr&amp;gt;
                &amp;lt;/thead&amp;gt;
                &amp;lt;tbody&amp;gt;
                    {users.map((user, key) =&amp;gt;
                        &amp;lt;tr key={key}&amp;gt;
                            &amp;lt;td&amp;gt;{user.id}&amp;lt;/td&amp;gt;
                            &amp;lt;td&amp;gt;{user.name}&amp;lt;/td&amp;gt;
                            &amp;lt;td&amp;gt;{user.email}&amp;lt;/td&amp;gt;
                            &amp;lt;td&amp;gt;{user.mobile}&amp;lt;/td&amp;gt;
                            &amp;lt;td&amp;gt;
                                &amp;lt;Link to={`user/${user.id}/edit`} style={{marginRight: "10px"}}&amp;gt;Edit&amp;lt;/Link&amp;gt;
                                &amp;lt;button&amp;gt;Delete&amp;lt;/button&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                    )}

                &amp;lt;/tbody&amp;gt;
            &amp;lt;/table&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Update index.php file for adding new GET API to get all users&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;case 'GET':
    $sql = "SELECT * FROM users";
    $stmt = $db-&amp;gt;prepare($sql);
    $stmt-&amp;gt;execute();
    $users = $stmt-&amp;gt;fetchAll(PDO::FETCH_ASSOC);        
    echo json_encode($users);
    break;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Load user details for edit form and create PHP PUT API to update user data&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update src/components/UpdateUser.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from "react";
import axios from "axios";
import { useNavigate, useParams } from "react-router-dom";
export default function ListUser() {
    const navigate = useNavigate();
    const [inputs, setInputs] = useState([]);
    const {id} = useParams();
    useEffect(() =&amp;gt; {
        getUser();
    }, []);
    function getUser() {
        axios.get(`http://localhost:8888/api/user/${id}`).then(function(response) {
            console.log(response.data);
            setInputs(response.data);
        });
    }
    const handleChange = (event) =&amp;gt; {
        const name = event.target.name;
        const value = event.target.value;
        setInputs(values =&amp;gt; ({...values, [name]: value}));
    }
    const handleSubmit = (event) =&amp;gt; {
        event.preventDefault();
        axios.put(`http://localhost:8888/api/user/${id}/edit`, inputs).then(function(response){
            console.log(response.data);
            navigate('/');
        });

    }
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;h1&amp;gt;Edit user&amp;lt;/h1&amp;gt;
            &amp;lt;form onSubmit={handleSubmit}&amp;gt;
                &amp;lt;table cellSpacing="10"&amp;gt;
                    &amp;lt;tbody&amp;gt;
                        &amp;lt;tr&amp;gt;
                            &amp;lt;th&amp;gt;
                                &amp;lt;label&amp;gt;Name: &amp;lt;/label&amp;gt;
                            &amp;lt;/th&amp;gt;
                            &amp;lt;td&amp;gt;
                                &amp;lt;input value={inputs.name} type="text" name="name" onChange={handleChange} /&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                        &amp;lt;tr&amp;gt;
                            &amp;lt;th&amp;gt;
                                &amp;lt;label&amp;gt;Email: &amp;lt;/label&amp;gt;
                            &amp;lt;/th&amp;gt;
                            &amp;lt;td&amp;gt; 
                                &amp;lt;input value={inputs.email} type="text" name="email" onChange={handleChange} /&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                        &amp;lt;tr&amp;gt;
                            &amp;lt;th&amp;gt;
                                &amp;lt;label&amp;gt;Mobile: &amp;lt;/label&amp;gt;
                            &amp;lt;/th&amp;gt;
                            &amp;lt;td&amp;gt;
                                &amp;lt;input value={inputs.mobile} type="text" name="mobile" onChange={handleChange} /&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                        &amp;lt;tr&amp;gt;
                            &amp;lt;td colSpan="2" align ="right"&amp;gt;
                                &amp;lt;button&amp;gt;Save&amp;lt;/button&amp;gt;
                            &amp;lt;/td&amp;gt;
                        &amp;lt;/tr&amp;gt;
                    &amp;lt;/tbody&amp;gt;
                &amp;lt;/table&amp;gt;
            &amp;lt;/form&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update get method to return specific user details by ID&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;case "GET": 
        $sql = "SELECT * FROM users";
        $path = explode('/', $_SERVER['REQUEST_URI']);
        if(isset($path[3]) &amp;amp;&amp;amp; is_numeric($path[3])) {
            $sql .= " WHERE id = :id";
            $stmt = $conn-&amp;gt;prepare($sql);
            $stmt-&amp;gt;bindParam(':id', $path[3]);
            $stmt-&amp;gt;execute();
            $users = $stmt-&amp;gt;fetch(PDO::FETCH_ASSOC);
        } else {
            $stmt = $conn-&amp;gt;prepare($sql);
            $stmt-&amp;gt;execute();
            $users = $stmt-&amp;gt;fetchAll(PDO::FETCH_ASSOC);
        }

        echo json_encode($users);
        break;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now create update API to Handle PUT request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;case "PUT": 
            $user = json_decode( file_get_contents('php://input') );
            $sql = "UPDATE users SET name= :name, email =:email, mobile =:mobile, updated_at =:updated_at WHERE id = :id";
            $stmt = $conn-&amp;gt;prepare($sql);
            $updated_at = date('Y-m-d');
            $stmt-&amp;gt;bindParam(':id', $user-&amp;gt;id);
            $stmt-&amp;gt;bindParam(':name', $user-&amp;gt;name);
            $stmt-&amp;gt;bindParam(':email', $user-&amp;gt;email);
            $stmt-&amp;gt;bindParam(':mobile', $user-&amp;gt;mobile);
            $stmt-&amp;gt;bindParam(':updated_at', $updated_at);

            if($stmt-&amp;gt;execute()) {
                $response = ['status' =&amp;gt; 1, 'message' =&amp;gt; 'Record updated successfully.'];
            } else {
                $response = ['status' =&amp;gt; 0, 'message' =&amp;gt; 'Failed to update record.'];
            }
            echo json_encode($response);
            break;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create DELETE PHP API, consume it using axios and delete user from database
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Update src/components/ListUser.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const deleteUser = (id) =&amp;gt; {
        axios.delete(`http://localhost:8888/api/user/${id}/delete`).then(function(response){
        console.log(response.data);
        getUsers();
    });
}
&amp;lt;button onClick={() =&amp;gt; deleteUser(user.id)}&amp;gt;Delete&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Update index.php again for writing delete API&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;case "DELETE": 
        $sql = "DELETE FROM users WHERE id = :id";
        $path = explode('/', $_SERVER['REQUEST_URI']);

        $stmt = $conn-&amp;gt;prepare($sql);
        $stmt-&amp;gt;bindParam(':id', $path[3]);
        if($stmt-&amp;gt;execute()) {
            $response = ['status' =&amp;gt; 1, 'message' =&amp;gt; 'Record deleted successfully.'];
        } else {
            $response = ['status' =&amp;gt; 0, 'message' =&amp;gt; 'Failed to delete record.'];
        }
        echo json_encode($response);
        break;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Awesome, you have just completed REACT-CRUD using PHP and MySQL, Now run you application and build something beautiful.&lt;/p&gt;

&lt;p&gt;You can download complete source code from GitHub:&lt;br&gt;
&lt;a href="https://github.com/durgesh-sahani/react-crud-php-api-mysql"&gt;https://github.com/durgesh-sahani/react-crud-php-api-mysql&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading this blog.&lt;/p&gt;

</description>
      <category>react</category>
      <category>php</category>
      <category>mysql</category>
    </item>
  </channel>
</rss>
