Fatal error: Call to a member function prepare() on a non-object in /home/wpviewer/domains/webpagevi
ik heb een probleem met mijn pdo prepare statement iemand die mij op deze fout kan wijzen
de connect gegegevens heb ik uit dit bestand verwijderd
alvast bedankt ralph
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?
class db {
function __construct ($tableName) {
$this->tableName = $tableName;
$this->fieldList = array();
$this->queryType = "insert";
$this->query = "";
$this->configArr = array();
}
// deze connect wordt nu nog gebruik wil gaan kijken of deze alleen kan worden uitgevoerd
// wanneer de class wordt aangeroepen
// standaard PDOconnect met als toevoeging een debug tool ($debug staat nu op true)
public static function connect ($server, $database, $username, $password, $debug = true ) {
try {
$db = new PDO("mysql:host=".$server."; dbname=".$database, $username, $pasword);
}
catch (PDOException $e) {
Debug::log_string('connection mysql : Error='.$e->getMessage());
die();
}
self::$debug_mode = $debug;
}
// nu een private functie van gemaakt kan later ok een public worden als dat nodig mocht zijn.
public function getArray ($query, $keyCol = false, $valueCol= false) {
try {
// moet tijdens het testen blijken of ik deze nodig heb of degene die er onder staat. als ik deze uitgecommande nodig heb even replacen in de hele class
//$res = self::$_connection->query($query);
$res = self::execQuery($query);
$arr = array();
// fetch array
while ($row = $res->fetch(PDO::FETCH_ASSOC))
{
$arr = $row;
}
}
catch (PDOException $e) {
if(self::$debug_mode)
{
Debug::log_string('Execute query: Query = '.$query.' Error = '.$e->getMessage().' Result = '.count($return));
}
}
if (!$keyCol) {
$arr[] = $geg;
} elseif (!$keyCol && $valueCol) {
$arr[] = $geg[$valueCol];
} elseif ($keyCol && $valueCol) {
$arr[$geg][$keyCol] = $geg[$valueCol];
} else {
$arr[$geg][$keyCol] = $geg;
}
return $arr;
}
// deze functie moet uitgebreid getest worden
public function getSingleResult ($query, $fieldName = false) {
$res = self::execQuery($query);
$geg = $res->fetchColumn();
if($fieldName) {
return $geg[$fieldName];
}else{
return $geg;
}
}
public function quickNumRows($query){
$res = self::execQuery($query);
return $res->rowCount();
}
public function quickFetch($query, $keys = false, $values = false) {
try {
$res = self::execQuery($query);
}
catch (PDOException $e) {
if(self::$debug_mode)
{
Debug::log_string('Execute query: Query = '.$query.' Error = '.$e->getMessage().' Result = '.count($return));
}
$retVal = array();
if($res->rowCount() == 1 && !$keys && !$values) {
$retVal = $res->fetch(PDO::FETCH_ASSOC);
}elseif($res -> rowCount() == 0){
return false;
}elseif($res->rowCount() > 1 || $keys || $values ) {
while($geg->fetch(PDO::FETCH_ASSOC)){
if(!keys && !$values) {
$retVal = $geg;
}elseif($keys && !$values) {
$retVal[$geg][$keys] = $geg;
}elseif($keys && $values) {
$retVal[$geg][$keys] = $geg[$values];
}elseif(!$keys && $values) {
$retVal = $geg[$values];
}
}
return $retVal;
}
}
}
public function stripHtml($str) {
return htmlentities($str);
}
function stripSlashesRecursive($array) {
foreach($array as $key=>$value) {
if(is_array($value)) {
$value=$this->stripSlashesRecursive($value);
$array_temp[$key]=$value;
} else {
$array_temp[$key]=stripslashes($value);
}
}
return $array_temp;
}
public function addField($fieldName, $fieldValue) {
if ($this->configArr[stripHtml]) {
$fieldValue = $this->stripHtml($fieldValue);
}
if ($this->configArr[stripSlashesRecursive]) {
if (is_array($fieldValue)) {
$fieldValue = base64_encode(serialize($this->stripSlashesRecursive($fieldValue)));
}
} else {
if (is_array($fieldValue)) {
$fieldValue = base64_encode(serialize($fieldValue));
}
}
$this->fieldList[$fieldName] = $fieldValue;
}
function setConfig($type) {
$this->configArr[$type] = true;
}
public function insert () {
$insertQuery = "INSERT INTO ".$this ->tableName." (";
$keyArr = array();
$valueArr = array();
$statementArr = array();
foreach($this->fieldList as $key => $value) {
$keyArr[] = $key;
$valueArr[] = "'".$value."'";
$statementArr[] ="':".$key."'";
}
$insertQuery .= join(", ", $keyArr);
$insertQuery .=") VALUES (";
$insertQuery .= join(", ", $statementArr);
$insertQuery .=")";
$prep = $db->prepare($insertQuery);
$I = 0;
foreach($statementArr as $statement) {
}
$this->query = $insertQuery;
echo $insertQuery;
}
}
?>
class db {
function __construct ($tableName) {
$this->tableName = $tableName;
$this->fieldList = array();
$this->queryType = "insert";
$this->query = "";
$this->configArr = array();
}
// deze connect wordt nu nog gebruik wil gaan kijken of deze alleen kan worden uitgevoerd
// wanneer de class wordt aangeroepen
// standaard PDOconnect met als toevoeging een debug tool ($debug staat nu op true)
public static function connect ($server, $database, $username, $password, $debug = true ) {
try {
$db = new PDO("mysql:host=".$server."; dbname=".$database, $username, $pasword);
}
catch (PDOException $e) {
Debug::log_string('connection mysql : Error='.$e->getMessage());
die();
}
self::$debug_mode = $debug;
}
// nu een private functie van gemaakt kan later ok een public worden als dat nodig mocht zijn.
public function getArray ($query, $keyCol = false, $valueCol= false) {
try {
// moet tijdens het testen blijken of ik deze nodig heb of degene die er onder staat. als ik deze uitgecommande nodig heb even replacen in de hele class
//$res = self::$_connection->query($query);
$res = self::execQuery($query);
$arr = array();
// fetch array
while ($row = $res->fetch(PDO::FETCH_ASSOC))
{
$arr = $row;
}
}
catch (PDOException $e) {
if(self::$debug_mode)
{
Debug::log_string('Execute query: Query = '.$query.' Error = '.$e->getMessage().' Result = '.count($return));
}
}
if (!$keyCol) {
$arr[] = $geg;
} elseif (!$keyCol && $valueCol) {
$arr[] = $geg[$valueCol];
} elseif ($keyCol && $valueCol) {
$arr[$geg][$keyCol] = $geg[$valueCol];
} else {
$arr[$geg][$keyCol] = $geg;
}
return $arr;
}
// deze functie moet uitgebreid getest worden
public function getSingleResult ($query, $fieldName = false) {
$res = self::execQuery($query);
$geg = $res->fetchColumn();
if($fieldName) {
return $geg[$fieldName];
}else{
return $geg;
}
}
public function quickNumRows($query){
$res = self::execQuery($query);
return $res->rowCount();
}
public function quickFetch($query, $keys = false, $values = false) {
try {
$res = self::execQuery($query);
}
catch (PDOException $e) {
if(self::$debug_mode)
{
Debug::log_string('Execute query: Query = '.$query.' Error = '.$e->getMessage().' Result = '.count($return));
}
$retVal = array();
if($res->rowCount() == 1 && !$keys && !$values) {
$retVal = $res->fetch(PDO::FETCH_ASSOC);
}elseif($res -> rowCount() == 0){
return false;
}elseif($res->rowCount() > 1 || $keys || $values ) {
while($geg->fetch(PDO::FETCH_ASSOC)){
if(!keys && !$values) {
$retVal = $geg;
}elseif($keys && !$values) {
$retVal[$geg][$keys] = $geg;
}elseif($keys && $values) {
$retVal[$geg][$keys] = $geg[$values];
}elseif(!$keys && $values) {
$retVal = $geg[$values];
}
}
return $retVal;
}
}
}
public function stripHtml($str) {
return htmlentities($str);
}
function stripSlashesRecursive($array) {
foreach($array as $key=>$value) {
if(is_array($value)) {
$value=$this->stripSlashesRecursive($value);
$array_temp[$key]=$value;
} else {
$array_temp[$key]=stripslashes($value);
}
}
return $array_temp;
}
public function addField($fieldName, $fieldValue) {
if ($this->configArr[stripHtml]) {
$fieldValue = $this->stripHtml($fieldValue);
}
if ($this->configArr[stripSlashesRecursive]) {
if (is_array($fieldValue)) {
$fieldValue = base64_encode(serialize($this->stripSlashesRecursive($fieldValue)));
}
} else {
if (is_array($fieldValue)) {
$fieldValue = base64_encode(serialize($fieldValue));
}
}
$this->fieldList[$fieldName] = $fieldValue;
}
function setConfig($type) {
$this->configArr[$type] = true;
}
public function insert () {
$insertQuery = "INSERT INTO ".$this ->tableName." (";
$keyArr = array();
$valueArr = array();
$statementArr = array();
foreach($this->fieldList as $key => $value) {
$keyArr[] = $key;
$valueArr[] = "'".$value."'";
$statementArr[] ="':".$key."'";
}
$insertQuery .= join(", ", $keyArr);
$insertQuery .=") VALUES (";
$insertQuery .= join(", ", $statementArr);
$insertQuery .=")";
$prep = $db->prepare($insertQuery);
$I = 0;
foreach($statementArr as $statement) {
}
$this->query = $insertQuery;
echo $insertQuery;
}
}
?>
Er zijn nog geen reacties op dit bericht.