Fatal error: Call to a member function query() on a non-object
ik heb onlangs een php applicatie op mijn server geplaats maar ik krijg steeds de volgende error:
Fatal error: Call to a member function query() on a non-object in C:\Inetpub\vhosts\survey.first-link.be\httpdocs\agenda\sa_session.php on line 48
Kunnen jullie mij helpen om dit probleem op te lossen?
Hieronder volgt de code van de sa_session.php pagina:
====================================
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
//----------------------------------------------------------------------
// Copyright 2003, 2004 SystemAct
// Voor licentievoorwaarden, zie licentie.txt
//----------------------------------------------------------------------
$register_globals = ini_get('register_globals');
function sa_session_unset($varname) {
global $register_globals;
if ($register_globals) {
session_unregister($varname);
}
else {
unset($_SESSION[$varname]);
}
}
function sa_session_open($save_path, $session_name) {
return true;
}
function sa_session_close() {
return true;
}
function sa_session_read($session_id) {
global $sadb;
$sql = "select session_data from sa_session where session_id = \"$session_id\"";
$result = $sadb->query($sql) or die($sql);
if ($record = $sadb->fetch_array($result)) {
return $record['session_data'];
}
else {
$timestamp = date("YmdHis", time());
$sql = "insert into sa_session
(session_id, session_timestamp, session_key, session_data)
values
(\"$session_id\", \"$timestamp\", \"\", \"\")";
$result = $sadb->query($sql) or die($sql);
return "";
}
}
function sa_session_write($session_id, $session_data) {
global $sadb;
$timestamp = date("YmdHis", time());
$session_data = addslashes($session_data);
$sql = "update sa_session
set session_timestamp = \"$timestamp\",
session_data = \"$session_data\",
where session_id = \"$session_id\" and session_key = \"\"";
$result = $sadb->query($sql);
return true;
}
function sa_session_destroy($session_id) {
global $sadb;
$sql = "delete from sa_session where session_id = \"$session_id\"";
$result = $sadb->query($sql);
return true;
}
function sa_session_gc($max_lifetime) {
global $sadb;
$timestamp = date("YmdHis", (time() - $max_lifetime));
$sql = "delete from sa_session where session_timestamp <= \"$timestamp\"";
$result = $sadb->query($sql);
return true;
}
session_set_save_handler("sa_session_open", "sa_session_close", "sa_session_read",
"sa_session_write", "sa_session_destroy", "sa_session_gc");
?>
//----------------------------------------------------------------------
// Copyright 2003, 2004 SystemAct
// Voor licentievoorwaarden, zie licentie.txt
//----------------------------------------------------------------------
$register_globals = ini_get('register_globals');
function sa_session_unset($varname) {
global $register_globals;
if ($register_globals) {
session_unregister($varname);
}
else {
unset($_SESSION[$varname]);
}
}
function sa_session_open($save_path, $session_name) {
return true;
}
function sa_session_close() {
return true;
}
function sa_session_read($session_id) {
global $sadb;
$sql = "select session_data from sa_session where session_id = \"$session_id\"";
$result = $sadb->query($sql) or die($sql);
if ($record = $sadb->fetch_array($result)) {
return $record['session_data'];
}
else {
$timestamp = date("YmdHis", time());
$sql = "insert into sa_session
(session_id, session_timestamp, session_key, session_data)
values
(\"$session_id\", \"$timestamp\", \"\", \"\")";
$result = $sadb->query($sql) or die($sql);
return "";
}
}
function sa_session_write($session_id, $session_data) {
global $sadb;
$timestamp = date("YmdHis", time());
$session_data = addslashes($session_data);
$sql = "update sa_session
set session_timestamp = \"$timestamp\",
session_data = \"$session_data\",
where session_id = \"$session_id\" and session_key = \"\"";
$result = $sadb->query($sql);
return true;
}
function sa_session_destroy($session_id) {
global $sadb;
$sql = "delete from sa_session where session_id = \"$session_id\"";
$result = $sadb->query($sql);
return true;
}
function sa_session_gc($max_lifetime) {
global $sadb;
$timestamp = date("YmdHis", (time() - $max_lifetime));
$sql = "delete from sa_session where session_timestamp <= \"$timestamp\"";
$result = $sadb->query($sql);
return true;
}
session_set_save_handler("sa_session_open", "sa_session_close", "sa_session_read",
"sa_session_write", "sa_session_destroy", "sa_session_gc");
?>
=================================
Alvast bedankt voor de hulp.
Aangezien dit ook een $sa__ is, zal er nog wel een $sa[db] (database) bijkomen.
Je mist dus nog een bestand, het bestand/code met daarin de class $sadb.
==================================
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
//----------------------------------------------------------------------
// Copyright 2003, 2004 SystemAct
// Voor licentievoorwaarden, zie licentie.txt
//----------------------------------------------------------------------
class Sa_db {
function Sa_db() {
}
function connect($server, $database, $user, $password) {
$connection = mysql_connect($server, $user, $password)
or die ("kon geen connectie maken");
mysql_select_db($database) or die ("kon subsidie database niet selecteren");
}
function query($sql) {
return mysql_query($sql);
}
function query_limit($sql, $offset, $limit) {
return mysql_query($sql . " limit $offset, $limit");
}
function query_insert_autoincrement($sql, $col) {
return mysql_query($sql);
}
function fetch_array($result) {
return mysql_fetch_assoc($result);
}
function result($result, $row, $field) {
return mysql_result($result, $row, $field);
}
function num_rows($result) {
return mysql_num_rows($result);
}
function insert_id() {
return mysql_insert_id();
}
}
?>
//----------------------------------------------------------------------
// Copyright 2003, 2004 SystemAct
// Voor licentievoorwaarden, zie licentie.txt
//----------------------------------------------------------------------
class Sa_db {
function Sa_db() {
}
function connect($server, $database, $user, $password) {
$connection = mysql_connect($server, $user, $password)
or die ("kon geen connectie maken");
mysql_select_db($database) or die ("kon subsidie database niet selecteren");
}
function query($sql) {
return mysql_query($sql);
}
function query_limit($sql, $offset, $limit) {
return mysql_query($sql . " limit $offset, $limit");
}
function query_insert_autoincrement($sql, $col) {
return mysql_query($sql);
}
function fetch_array($result) {
return mysql_fetch_assoc($result);
}
function result($result, $row, $field) {
return mysql_result($result, $row, $field);
}
function num_rows($result) {
return mysql_num_rows($result);
}
function insert_id() {
return mysql_insert_id();
}
}
?>
================================
En hier de code van app_init.php:
================================
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
//----------------------------------------------------------------------
// Copyright 2003, 2004 SystemAct
// Voor licentievoorwaarden, zie licentie.txt
//----------------------------------------------------------------------
include_once('config/connect.php');
include_once('db_drivers/sa_mysql.php');
$sadb = &new Sa_db();
$sadb->connect($server, $database, $user, $password);
require_once('sa_session.php');
session_start();
class user {
var $username;
var $is_admin;
var $roles = array();
function addRole($role) {
$this->roles[] = $role;
}
function clearRoles() {
$this->roles = array();
}
function hasRole($role) {
return in_array($role, $this->roles);
}
}
if (!isset($_SESSION[$app_id])) {
$user_obj = &new user();
$user_obj->username = 'anonymous';
// user 'anonymous' heeft automatisch de rol 'anonieme gebruiker'
$user_obj->addRole(1);
$_SESSION[$app_id] = $user_obj;
}
else {
$user_obj = $_SESSION[$app_id];
}
?>
//----------------------------------------------------------------------
// Copyright 2003, 2004 SystemAct
// Voor licentievoorwaarden, zie licentie.txt
//----------------------------------------------------------------------
include_once('config/connect.php');
include_once('db_drivers/sa_mysql.php');
$sadb = &new Sa_db();
$sadb->connect($server, $database, $user, $password);
require_once('sa_session.php');
session_start();
class user {
var $username;
var $is_admin;
var $roles = array();
function addRole($role) {
$this->roles[] = $role;
}
function clearRoles() {
$this->roles = array();
}
function hasRole($role) {
return in_array($role, $this->roles);
}
}
if (!isset($_SESSION[$app_id])) {
$user_obj = &new user();
$user_obj->username = 'anonymous';
// user 'anonymous' heeft automatisch de rol 'anonieme gebruiker'
$user_obj->addRole(1);
$_SESSION[$app_id] = $user_obj;
}
else {
$user_obj = $_SESSION[$app_id];
}
?>
==============================
Als er nog iets ontbreekt, vraag maar.
Gewijzigd op 01/01/1970 01:00:00 door Olivier