duchaine1 Posted August 15, 2022 Share Posted August 15, 2022 Hi, Being somewhat new to the subject I ALREADY have the connection code to database, what I need is WHERE to place it. In other words where do I put THIS... <?php $conn = mysqli_connect( <location-of-your-database>, <your-MySQL database-username>, '<your-MySQL-database-password>, and so on. It is all done and ready to go. So, do I put it in index.html, no good, DB error so where does it go? Also is it a <PHP> page? Surprisingly this is hard to find. Everybody talks in detail about the script, but NOBODY mentions where it is placed! Thanks! Duchaine (du shane) Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 15, 2022 Share Posted August 15, 2022 by default, only files with a .php extension will be operated on by the php language engine. the code in for any .php page should be laid out in this general order - initialization post method form processing get method business logic - get/produce data needed to display the page html document the database connection would be made at the earliest point where it is needed, usually in the initialization section. if you are just starting out, the PDO extension is much simpler and better designed then the mysqli extension, especially when using prepared queries, which you should be using when supplying external, unknown, dynamic values to a query when it gets executed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.