Jump to content

Moving some PHP to the backend without a button press or anything


Recommended Posts

I am trying to find a good IDE for PHP and JavaScript.  I fiddled around with Visual Code and it was very buggy.  The GitHub page said over 800 open errors?!?!?  Now I'm looking at PHPStorm and it reads that only PHP in a PHP page or JavaScript in a JavaScript page may be debugged.  I am wondering if this is always  possible to separate the code like this.

 

Also, in the following code, what do you all think about using a XMLHttpRequest() to call this right in the beginning of the page with no button or anything.   Is this bad form?  It creates a dropdown list from the database.  Right now it just sits there.  This code isn't ready for prepare yet.

 

<?php

$host = 'localhost';
$user = 'root';
$pass = '';
$database = 'ecommerce';

$options = array(
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_EMULATE_PREPARES => false
);

$dbo = new PDO("mysql:host=$host;dbname=$database", $user, $pass, $options);

$q4 = "SELECT categories.title FROM categories INNER JOIN customers on customers.CustomerID = categories.CustomerID and customers.CustomerID = 1";

echo '<select id = "dropDown1" >';

foreach ($dbo->query($q4) as $row) {
    echo "<br>";
echo  '<option value = " ';

echo  $row['title'];
echo '">';
echo $row['title'];
echo '</option>';

}
echo "<br>";
echo  '</select>';

?>

I'm using AJAX.

 

 

 

 

 

Edited by JoshEir

In my experience, VSCode is not at all buggy; I've used PHPStorm and - personally - didn't like the project setup aspect of things. That having been said, I have to say that setting up a debugger is much easier with PHPStorm than VSCode, and all of my co-workers use PHPStorm and love it. So honestly, check out some plugins, give both a fair shake, and use what helps you get the work done.

As for the code using ajax on page load, it kinda depends. Is this a page that you're gathering analytics or is it reliant on search engine rankings? If so, you're probably going to want to have content available when the page loads. If it's part of an SPA after the user has logged in, then you can do a fetch on page load. Or you can server-side render the initial page content, then use ajax or fetch to update and/or change that data depending on the user action.

  • Like 1
18 hours ago, JoshEir said:

I am trying to find a good IDE for PHP and JavaScript.  I fiddled around with Visual Code and it was very buggy.  The GitHub page said over 800 open errors?!?!?  Now I'm looking at PHPStorm and it reads that only PHP in a PHP page or JavaScript in a JavaScript page may be debugged.  I am wondering if this is always  possible to separate the code like this.

 

Javascript debugging is done in the browser using the built-in developer tools.  People typically use chrome.  The exception would be if you have a node application or javascript front end application built on vue or react etc. but in that case you are going to have the front end code separate from the back end code, and be implementing a REST api or something similar on your backend, which is basically what you would want to do for any ajax calls.

If you have lots of mixed PHP/HTML scripts you can still debug those with the PHP debugger, but it's really not a great way to develop clean maintainable code.

Most pro developers use PHPStorm.  It's not free obviously, but it's the premier solution.  It has so many options it can actually be pretty daunting, but it also provides the best navigation through a complicated code base of any IDE.  As for free options, I have also used phpeclipse, which is built on top of eclipse.  It's not terrible, as Zend for a time had a commercial product based on it, but Zend no longer exists as a company.  Lately I'm using Visual Studio Code, but I haven't made a lot of efforts to get it setup for PHP.  It's really where a lot of the web development community has migrated, and the support and velocity of enhancements is very high.

  • Like 1

I am playing with PHPStorm and Visual Code at the same time.  I finally got Visual Code working again, the program.  PHPStorm won't set me back, I think it is a good price at around nine dollars a month with a month to consider.  

Using Visual Code for PHP and JavaScript I can run in parallel which is nice.  However, I am having problem with the red JavaScript breakpoint turning to a grey outlined breakpoint after Chrome is launched.  The debugger doesn't stop there.

Using Chrome Developer Tools doesn't seem to be an option for me because It doesn't seem possible to access more than one page to debug with breakpoints.

Do you understand it the same way?

Josh

I think the point you are making, is that there is no holistic cross language debugging tool, but then again that is the nature of web development.  There are a lot of different languages and ways you can connect things, which require different debugging tools. In recent years most of my projects have been done with either Symfony or Laravel, and they both offer a debugging toolbar that tries to bridge the gap somewhat, but at the end of the day, I find there are a number of different tools and techniques you need for debugging.  The same is probably true of any networked system, where there are a variety of services that are connected in a non-trivial way.

From a front end standpoint, the more complicated the javascript, the more you need to use the developer tools.  More often than not, I'm looking at the network tab and looking at the request/response data.  I'm typically only using the javascript debugger when I have something specific that I know is broken in a particular way.  If I'm not sure exactly where thing are going wrong, then I'll step through the code by placing a breakpoint at an early/well known point.  At the end of the day, once code is running in the browser, it is no longer something you can debug from the serverside.  

  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.