I'm just starting to learn PHP. I have three random questions about PHP and one question about Code Review. None of them are technical questions ("will this work?"); they're best practices questions ("is this the best way to do this?"). Can you offer advice?
I put commonly used data in separate files and use include to insert them into other pages. This avoids typing the exact same code into dozens of files. Is that considered a best practice? Is there a better way to organize common page elements? An example: A file named footer.php:
<?php echo "<p>Copyright Michael</p><p><a href="index.html">Go home</a></p>" ?>
And a snippet that's in all my other files:
<div id="footer"> <?php include "footer.php ?> </div>
What's the best way to store a MySQL connect string? I saved it in a separate "util.php" file. It reads something like:
<?php $con=mysqli_connect("localhost","admin","password","devDatabase"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?>
All files that connect to the db have:
<?php include "util.php" ?>
Is than an efficient and/or secure way to store the connection string?
What PHP frameworks do you recommend? I'm trying to get a solid understanding of PHP/Javascript/MySQL for basic web design. After that, should I select a particular PHP framework? Or should I skip PHP and move to a newer language like Ruby on Rails?
Finally, can I get feedback by posting my URL here? If I list www.mynewsite.com and post the code for the main PHP files, could I get general feedback on the site?