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 9198783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:22:08+00:00 2026-06-17T22:22:08+00:00

Let’s say I’m creating a basic page, said page’s text varies depending on what’s

  • 0

Let’s say I’m creating a basic page, said page’s text varies depending on what’s passed into it through a GET variable.

There’s a header at the top of the page like so:

<?php 
mysql_connect("stuff", "stuff", "stuff");
mysql_select_db("dbname");
mysql_query("SELECT * FROM table WHERE ID = '{$_GET['url']}'");

//Now we have connected to the SQL database.
?>

Assuming I continued coding there, so that the header text varied depending on what was passed into the URL (however, this is irrelevant, it’s the next part in which I want to question).

Now let’s say that, further down the page, there is some more PHP code, but there is also more HTML code in between. If I wanted to access the database again in this second PHP snippet, do I have to reconnect to the database? Or is there a way I can make sure that the connection session stays open, even when it’s a completely different <?php ?> area? How do i make it so that my SQL connection isn’t dropped when I end the <?php tag?

  • 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-06-17T22:22:10+00:00Added an answer on June 17, 2026 at 10:22 pm

    Let’s address several issues at once 🙂

    1. The connection will not be dropped unless you explicitly do it yourself. It will be dropped when the script ends, of course. Even then, there are techniques of persistent connection and connection pooling that may help you avoid the overhead.

    2. The mysql_* family of functions is deprecated and may soon cease working altogether. You’d be much better off by moving to e.g. PDO functions, which are more powerful and safer too.

    3. When you put a _GET parameter directly inside a SQL query (or other server code) without checking/validating, you expose yourself to the danger of that parameter containing some nasty surprise. The classic example, apart from XKCD, is if you check that $_GET['password'] corresponds to field password. If you just code it as

    WHERE ... password = '$_GET[password]'
    

    and someone places in that field the value

    ' OR ''=='
    

    the SQL server will see

    WHERE ... password = '' OR ''==''
    

    and since ” is indeed equal to ”, that query will return true — and the user will be logged in without knowing the password. Such "SQL injection", if possible at all, can often be tuned to the point of allowing an attacker to be recognized as the site’s administrator, with all that entails. And that’s why you don’t want to use client-side parameters "as is". PDO’s prepared statements can help there, too.

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

Sidebar

Related Questions

Let's say I have pseudocode like this: main() { BOOL b = get_bool_from_environment(); //get
Let's say I wish to connect to a remote computer through IP address, and
Let's say you're trying to set a label's text. By doing it, you call
Let's say I have a 1 GB text file and I want to read
Let's say I have to use an ASP master page and setup a Kendo
Let's say I've got two files class.php and page.php class.php <?php class IUarts {
Let's say I get a PreparedStatement from a Connection object, and then later I
Let's say, I've got a XmlNode: <A>1</A> How to remove a text from it,
Let's say I'm creating an OpenGL game in C++ that will have many objects
Let's say I query for http://images.google.com.sg/images?q=sky&imgcolor=black and I get all the black color sky,

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.