Jump to content

how to connect php to mysql


duchaine1

Recommended Posts

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)

 

 

Link to comment
Share on other sites

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 -

  1. initialization
  2.  post method form processing
  3. get method business logic - get/produce data needed to display the page
  4. 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.

Link to comment
Share on other sites

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.