Jump to content

Recommended Posts

I am still having trouble with this query below : (Please Help!!!)

[code]
<?php

require_once('constants.php');

$DEBUG = 0;

$SESS_LIFE = get_cfg_var("session.gc_maxlifetime");

        function sess_open($save_path, $session_name) {
          return true;
        }

        function sess_close() {
          return true;
        }

        function sess_read($key) {
                global $DEBUG, $SESS_LIFE;

$statement = "SELECT * FROM sessions WHERE sesskey = '$key' AND expiry > " . time();
                $result = mssql_query($statement) or die ('Query failed.');  // This is Line 21

                if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
               
if ($result) {
$row = mssql_fetch_assoc($result);
return $row['value'];
}
return false;
        }
?>
[/code]

Also posted everything above it to show how lib.session_handler.php is being run.
The Error I am getting is this one here :

Query failed.PHP Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'sessions'. (severity 16) in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 21 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 21

I have tried a number of things and you can find more details by [url=http://www.phpfreaks.com/forums/index.php/topic,105051.0.html]going here[/url]
I have been on this problem for over a week now and it is doing my head in  ???

As you can find from the previous post that it is now using one connection as shown here :

[code]
<?php

function connect()
      {

        // connect to the database

mssql_connect($INTRANET_DB_URL);
$this->connected == TRUE or die;
  $this->connected == FALSE;
mssql_select_db($AUTH_DB_TBL);
$this->connected == TRUE or die;
$this->connected == FALSE;
  }

?>
[/code]

As found in file class.PHPApplication.php
These constants are defined here in config.inc.php :

[code]
<?php

    $AUTH_DB_USERNAME     = 'user';
    $AUTH_DB_PASSWD       = 'pass';
    $AUTH_DB_HOST = 'localhost';
    $AUTH_DB_NAME = 'mri_sql';
    $AUTH_DB_TBL                  = 'users';

$INTRANET_DB_URL = '"' . $AUTH_DB_HOST . '"' . ',' . '"' . $AUTH_DB_USERNAME . '"' . ',' . '"' . $AUTH_DB_PASSWD . '"';
$AUTH_DB_URL        = $INTRANET_DB_URL;
$USER_DB_URL        = $INTRANET_DB_URL;
$APP_DB_URL = $INTRANET_DB_URL;

// some other code

//  require_once 'DB.php';
 
  require_once 'constants.php';
  require_once $APPLICATION_CLASS;
  require_once $ERROR_HANDLER_CLASS;
  require_once $AUTHENTICATION_CLASS;
//  require_once $DBI_CLASS;
//  require_once $THEME_CLASS;
//  require_once $THEME_TEMPLATE_CLASS;
  require_once $USER_CLASS;
  require_once $TEMPLATE_CLASS;

?>
[/code]

This config file is called by the Application config files.  In this case login.conf.php.  Which is called by login.php, the Application class that extends class.PHPApplication.php, the backbone of my project which connects the database as seen above.

I hope there is enough info here and on the [url=http://www.phpfreaks.com/forums/index.php/topic,105051.0.html]other page[/url] linked to help you help me solve this, I can't move on untill this is sorted. Thanks
Link to comment
https://forums.phpfreaks.com/topic/18994-still-cant-get-this-query-to-work-solved/
Share on other sites

you need to create the connection before using mysql_query();

change your open function to:[code]<?php
function sess_open($save_path, $session_name) {
    global $SESS_LINK;
    if ($SESS_LINK = mysql_connect('host', 'user', 'pass')) {
        return mysql_select_db('databasethatcontainsthesessiontable');
    } else {
        return false;
    }
}
[/code]

You'll also need to update you other functions to specify the global $SESS_LINK resource in all mysql_query() functions.
Ok,  Now this is my lib.session_handler.php
[code]
<?php

require_once('constants.php');

$DEBUG = 0;

$SESS_LIFE = get_cfg_var("session.gc_maxlifetime");

        function sess_open($save_path, $session_name) {
          global $SESS_LINK;
  if ($SESS_LINK = mssql_connect('localhost', 'user', 'pass')) {
  return mssql_select_db('mri_sql');
  } else {
  return false;
  }
        }

        function sess_close() {
          return true;
        }

        function sess_read($key) {
                global $DEBUG, $SESS_LIFE, $SESS_LINK;

$statement = "SELECT * FROM sessions WHERE sesskey = '$key' AND expiry > '" . time() . "'";
                $result = mssql_query($statement);
echo "<br />" . msql_error() . "<br />\n";

                if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
               
if ($result) {
$row = mssql_fetch_assoc($result);
return $row['value'];
}
return false;
        }

        function sess_write($key, $val) {
                global $SESS_LIFE, $SESS_LINK;

                $expiry = time() + $SESS_LIFE;
                $value = addslashes($val);

                $statement = "INSERT INTO sessions VALUES ('$key', $expiry, '$value')";
                mssql_query($statement) or die ('Query failed.'); // this is line 45

                if ($DEBUG) echo "sess_write: $statement <br>result: $result<br>";

                if (! $result) {
                        $statement = "UPDATE sessions SET expiry = $expiry, value = '$value' " .
                              "WHERE sesskey = '$key' AND expiry > " . time();
                        mssql_query($statement) or die ('Query failed.');
                }

                return $result;
        }

        function sess_destroy($key) {

global $SESS_LINK;
                $statement = "DELETE FROM sessions WHERE sesskey = '$key'";
                $result = mssql_query($statement);
                if ($DEBUG) echo "sess_destroy: $statement <br>result: $result<br>";

                return $result;
        }

        function sess_gc($maxlifetime) {

                global $SESS_LINK;
$statement = "DELETE FROM sessions WHERE expiry < " . time();
                $qid = mssql_query($statement);
                if ($DEBUG) echo "sess_gc: $statement <br>result: $result<br>";

                return 1;
        }

        session_set_save_handler(
                "sess_open",
                "sess_close",
                "sess_read",
                "sess_write",
                "sess_destroy",
                "sess_gc");
?>
[/code]

Now it gets past sess_read and displays the same error for line 45 sess_write function :

Query failed.PHP Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'sessions'. (severity 16) in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 45 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 45

Why would this be if it worked on the one above?  Thanks for your help
Jenk I only have one connection, but what do you mean by namespace?  My directory structure is like so :

|
+-Database
|      +-Classes
|      |      | // lib.session_handler.php is in here
|      |      | // All my classes
|      +-httpd
|      |    +-images
|      |    +-index.php
|      |    +-styles.css
|      +-library
|      |    +-PEAR
|      |    +-php
|      +-scripts
|      |    +-login
|      |    +-home
|      |    +-customers
|      |    +- // You get the idea
|      +-Templates
|      |    | // All my templates
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.