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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:50:48+00:00 2026-06-05T21:50:48+00:00

Possible Duplicate: Close mysql connection (PHP) Please help me, I not know where add

  • 0

Possible Duplicate:
Close mysql connection (PHP)

Please help me, I not know where add mysql_close($db) ;

See my code:

<?php 

    class atsilipimai {

    private $db;

    public function __construct($host, $user, $password, $db) {

    $this->db = mysql_connect($host, $user, $password) or die('Couldn\'t connect to mysql');
    mysql_select_db($db) or die('Couldn\'t connect to db');
    }

    public function  addPost() {
    if ( isset($_POST['submit']) ) {
            $this->name = mysql_real_escape_string(addslashes($_POST['name']));
            $this->msg = mysql_real_escape_string(addslashes($_POST['msg']));
            $this->date = date("Y-m-d H:i:s");



            if (empty($this->name) || empty($this->msg)) {
                echo "<p>Please enter all details!</p>";
            } else {
                $sql = "INSERT INTO atsiliepimai (name, msg, date)";
                $sql .= " VALUES ('$this->name', '$this->msg', '$this->date')";
                mysql_query($sql) or die(mysql_error());

            }
        }
    }

    public function showPost() {
        //I'm not adding pagination, so it will only show last 5 posts.
        $sql = 'SELECT * FROM atsiliepimai ORDER BY id DESC LIMIT 5';
        $query = mysql_query($sql) or die('Couldn\'t get posts from database');
        while ( $row = mysql_fetch_array($query) ) {
            $this->name = htmlentities(stripslashes($row['name']));
            $this->msg = htmlentities(stripslashes($row['msg']));
            $this->date = htmlentities(stripslashes($row['date']));


            //Just add div's or what you want for the output.
            //Ip wont be added.
            echo "
            <h4>".$this->name."</h4>
            <p>".$this->msg."</p>
            <p class = 'data' >".$this->date."</p>
            <hr />
            ";

        }

    }

    public function __destruct() {



    }

    }
?>
  • 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-05T21:50:51+00:00Added an answer on June 5, 2026 at 9:50 pm

    From manual mysql_close

    Using mysql_close() isn’t usually necessary, as non-persistent open links are automatically closed at the end of the script’s execution.

    So you do not need to close it, unless you have some special cases you need to terminate connection then put this function.

    Also please use mysqli_* or PDO for interaction with database as mysql_* function deprecation preocess started

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

Sidebar

Related Questions

Possible Duplicate: PHP code is not being executed (i can see it on source
Possible Duplicates: using mysql_close() close mysql connection important? What are the benefits of closing
Possible Duplicate: close mysql connection important? How important is it close an mysql connection
Possible Duplicate: E-mail validation in php? please help I have Ajax sign up form.
Possible Duplicate: Do I need to use mysql_close(connection)? Is it best to close a
Possible Duplicate: Cross-thread operation not valid I am trying to close the base of
Possible Duplicate: How to parse HTML with PHP? Get MySQL database output via PHP
Possible Duplicate: php echo vs open&close tag For example. Is this: <p>Hello welcome to
Possible Duplicate: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result I have
Possible Duplicate: How do I read a “,” as “<br />” in PHP/MySQL? This

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.