Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3234650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:24:58+00:00 2026-05-17T17:24:58+00:00

I’m just learning PHP and I’m trying to figure out how I could store

  • 0

I’m just learning PHP and I’m trying to figure out how I could store my database queries in a separate file either as part of a class, method or just as simple variables.

For example: I have a query that looks like this:

$checkuser = mysql_query("SELECT UserName, Email FROM users 
                            WHERE UserName = '$username4db' OR EMAIL = '$email4db'") 
             or die($checkuser_error);

Instead of writing it inline within the file, I’d like to move this to a central place and then use them from there.

I tried using an include file and simply calling the variable in place but it doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:24:59+00:00Added an answer on May 17, 2026 at 5:24 pm

    You should look at the MVC design pattern, the whole purpose is to provide a clean way of organizing code based on function.

    The models are where your database interaction code goes. Depending on the MVC implementation this is sometimes a direct representation of the database table, or it could be a collection of functions you write yourself to deal with the problem at hand.

    The views are for display code. As a general rule when writing views only HTML and basic PHP (echoing variables, a foreach loop to build a table) should go in the view.

    The controller is where the program logic is placed. From the controller you call models to do the data processing necessary to build the data that is then passed into the view.

    That’s a very basic explanation, and always wikipedia has more to say on the topic: http://en.wikipedia.org/wiki/Model-view-controller.

    There are many MVC frameworks out there in PHP that you can use to have a good starting point for building sites. I use and recommend CodeIgniter as it’s very easy to use and flexible in its implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.