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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:28:18+00:00 2026-05-31T22:28:18+00:00

I little while back I posted this question . I have updated that question

  • 0

I little while back I posted this question. I have updated that question with the AJAX script that worked for about 1 week. Basically I can use session_start() from the AJAX script, and then I could access the session variables that I needed.

It is really strange, but I came in after the weekend, and this morning this script does not work anymore. It is very simple, here:

<?php

session_start();

$ajax_connection = mysql_connect('10.X.X.X',$_SESSION['username'],$_SESSION['password']);

$result_set = array();

while ($result_set[] = mysql_fetch_assoc($results)){
    // do nothing
}

echo json_encode($results);

?>

Last week this worked flawlessly, and now in my error log i get the Undefined index: username and Undefined index: password warnings. And of course the MySQL connection is not established. So this script is not running the same session as the original connection. I used error_log(session_id()) to check the IDs of the parent page and the AJAX script, and sure enough they are different. When i reload the page and try every again, the IDs stay the same for the page and the AJAX script respectively, but they should be the same ID, not 2 different ones.

Anyway, does anyone have any idea why this wouldn’t be working anymore, after working well for over a week?

  • 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-31T22:28:20+00:00Added an answer on May 31, 2026 at 10:28 pm

    Here’s the kind of Class you can use. It is in singleton to make sure you instanciate it only once. Instanciate it with

    $db = Db::getInstance();
    

    then

    $db->connect();
    

    this is a much safer way to use Dbase connections (Note that I used PDO, but if you really need to keep using mysql_ functions, you can still modify it).

    class Db {
    
        private static $instance = null;
        private $db = null;
        private $host = '';
        private $name = '';
        private $username = '';
        private $password = '';
    
        private function __construct() {
            $this->host = 'yourHost';
            $this->name = 'yourDbName';
            $this->username = 'yourUserName';
            $this->password = 'youPassword';
        }
    
        public static function getInstance() {
            if(is_null(self::$instance)) {
                self::$instance = new Db();
            }
            return self::$instance;
         }
    
         public function connect() {
            try {
                $this->db = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->name, $this->username, $this->password);
            } catch(Exception $e) {
                throw new Exception('Connection error: either the database is unavailable or connection infos are not valid. Please contact the webmaster.');
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to this question I asked a little while back. The
I asked a little while ago a question about rollback, I have a new
Back story i have a table that stores cached times, and currently has about
A while back I was reading about multi-variable assignments in PowerShell. This lets you
A while back, I learned a little bit about big O notation and the
I posted a similar question a while back and now as I need to
I've installed passenger a little while back and when I restarted my mac tonight,
I have been using IoC for a little while now and I am curious
We have had SharePoint where I work for a little while now, but we've
I have been learning to use Emacs for a little while now. So far

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.