Learning PHP is fun but sometimes I am always confused with some topics when I go through it, especially when I am reviewing those after a few days. Here is the list of questions and answer of it.
You can use Leetcode to do quick code. You can review a quick PHP guide before appearing for an interview.
Q. Why we are always using echo where the print is also an output function?
Because echo can take multiple arguments & echo is fast.
Q. Why do we have form element id when we access it using the name property?
Because the form element id must match with a label for property & using id we can access that form element in JS.
Q. Why we do form JS validation on form submit event but not on submit button click event?
Because if we do on click event on submit button, it stops its default behavior and just returns true or false but not submitting the form afterward. So we are doing that on the form ‘on submit’ event so if returns false stops the form to submit on the server.
Q. Formate of DSN in PDO always confused me.
DSN is a string so you will not get help from editor intelligence.
$dsn = mysql:hostname=‘ . $hostname . ‘;dbname=‘ . $dbname;
driver name then colon :
use hostname=
use semicolon ;
use dbname=
Q Best way to connect with DB
Use PDO class. Create dsn string, create an object of PDO class, and if you are not using select *(all) then use prepare, bind & execute statement. Check numrows() if it is greater than 0 then fetchall() data in a while loop.
Q How to send Ajax Request?
First, create an object named xhr, and use an open method xhr.open(), Create a callback function for event xhr,onload, and use send method finally xhr.send().