string-klasse-stmt-achtig
Gesponsorde koppelingen
PHP script bestanden
stringClass.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
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
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
<?php
/*----------------------------------------------
-------------------------------------------------
DONT REMOVE THIS BLOCK!!!
--------------------------------------------------------
Copyright
Created by: libia
Created on: 15-09-07 (DD-MM-YY)
--------------------------------------------------------
You can use this script,
but you may NOT call it YOUR script!
--------------------------------------------------------
-----------------------------------------------------*/
//the class
class String
{
//some variables
public $error;
public $errno;
protected $string;
protected $finalString;
protected $aantArgs;
protected $bindArgs;
protected $prepared;
protected $bonden;
protected $paramAant;
//setting values for the variables
function __construct()
{
$this->error = "No error's yet";
$this->errno = 0;
$this->string = '';
$this->finalString = '';
$this->aantArgs = 0;
$this->bindArgs = '';
$this->prepared = false;
$this->bonden = false;
$this->paramAant = 0;
}
//setting the first sentance
function prepare($prepareString)
{
if($this->errno == 0)
{
if(!$this->prepared)
{
if(!empty($prepareString))
{
$this->string = htmlspecialchars($prepareString, ENT_QUOTES);
$this->prepared = true;
}
else
{
$this->error = "String is empty!";
$this->errno = 1001;
}
}
else
{
$this->error = "String is already prepared!";
$this->errno = 1000;
}
}
}
//add the user values
function bind_param()
{
if($this->errno == 0)
{
if($this->prepared)
{
$this->bindArgs = func_get_args();
$this->aantArgs = count($this->bindArgs);
if($this->param_count() == $this->aantArgs)
{
$this->finalString = $this->string;
for($i = 0; $i < $this->aantArgs; $i++)
{
$this->finalString = preg_replace("/\?/", htmlspecialchars($this->bindArgs[$i], ENT_QUOTES), $this->finalString, 1);
}
$this->bonden = true;
}
elseif($this->param_count() > $this->string)
{
$this->error = "Not enough arguments given in the bind_param() function (" . $this->aantArgs . " of " . $this->param_count() . ")";
$this->errno = 1004;
}
else
{
$this->error = "To much arguments given in the bind_param() function (" . $this->aantArgs . " of " . $this->param_count() . ")";
$this->errno = 1005;
}
}
else
{
$this->error = "String not prepared yet!";
$this->errno = 1002;
}
}
}
//return the string
function execute()
{
if($this->errno == 0)
{
if($this->prepared && $this->bonden)
{
return $this->finalString;
}
elseif(!$this->prepared)
{
$this->error = "String not prepared yet!";
$this->errno = 1002;
}
else
{
$this->error = "Params are not bonden yet!";
$this->errno = 1003;
}
}
}
//gives the amount of question marks (?) is the sentence
function param_count()
{
if($this->errno == 0)
{
$this->paramAant = 0;
if($this->prepared)
{
for($i = 0; $i < strlen($this->string); $i++)
{
if($this->string[$i] == '?')
{
$this->paramAant += 1;
}
}
return $this->paramAant;
}
else
{
$this->error = "String not prepared yet!";
$this->errno = 1002;
}
}
}
//clears the results
function free_result()
{
$this->finalString = '';
$this->aantArgs = 0;
$this->bindArgs = '';
$this->string = '';
}
//sets everything to it's standard value
function close()
{
$this->__construct();
}
}
?>
/*----------------------------------------------
-------------------------------------------------
DONT REMOVE THIS BLOCK!!!
--------------------------------------------------------
Copyright
Created by: libia
Created on: 15-09-07 (DD-MM-YY)
--------------------------------------------------------
You can use this script,
but you may NOT call it YOUR script!
--------------------------------------------------------
-----------------------------------------------------*/
//the class
class String
{
//some variables
public $error;
public $errno;
protected $string;
protected $finalString;
protected $aantArgs;
protected $bindArgs;
protected $prepared;
protected $bonden;
protected $paramAant;
//setting values for the variables
function __construct()
{
$this->error = "No error's yet";
$this->errno = 0;
$this->string = '';
$this->finalString = '';
$this->aantArgs = 0;
$this->bindArgs = '';
$this->prepared = false;
$this->bonden = false;
$this->paramAant = 0;
}
//setting the first sentance
function prepare($prepareString)
{
if($this->errno == 0)
{
if(!$this->prepared)
{
if(!empty($prepareString))
{
$this->string = htmlspecialchars($prepareString, ENT_QUOTES);
$this->prepared = true;
}
else
{
$this->error = "String is empty!";
$this->errno = 1001;
}
}
else
{
$this->error = "String is already prepared!";
$this->errno = 1000;
}
}
}
//add the user values
function bind_param()
{
if($this->errno == 0)
{
if($this->prepared)
{
$this->bindArgs = func_get_args();
$this->aantArgs = count($this->bindArgs);
if($this->param_count() == $this->aantArgs)
{
$this->finalString = $this->string;
for($i = 0; $i < $this->aantArgs; $i++)
{
$this->finalString = preg_replace("/\?/", htmlspecialchars($this->bindArgs[$i], ENT_QUOTES), $this->finalString, 1);
}
$this->bonden = true;
}
elseif($this->param_count() > $this->string)
{
$this->error = "Not enough arguments given in the bind_param() function (" . $this->aantArgs . " of " . $this->param_count() . ")";
$this->errno = 1004;
}
else
{
$this->error = "To much arguments given in the bind_param() function (" . $this->aantArgs . " of " . $this->param_count() . ")";
$this->errno = 1005;
}
}
else
{
$this->error = "String not prepared yet!";
$this->errno = 1002;
}
}
}
//return the string
function execute()
{
if($this->errno == 0)
{
if($this->prepared && $this->bonden)
{
return $this->finalString;
}
elseif(!$this->prepared)
{
$this->error = "String not prepared yet!";
$this->errno = 1002;
}
else
{
$this->error = "Params are not bonden yet!";
$this->errno = 1003;
}
}
}
//gives the amount of question marks (?) is the sentence
function param_count()
{
if($this->errno == 0)
{
$this->paramAant = 0;
if($this->prepared)
{
for($i = 0; $i < strlen($this->string); $i++)
{
if($this->string[$i] == '?')
{
$this->paramAant += 1;
}
}
return $this->paramAant;
}
else
{
$this->error = "String not prepared yet!";
$this->errno = 1002;
}
}
}
//clears the results
function free_result()
{
$this->finalString = '';
$this->aantArgs = 0;
$this->bindArgs = '';
$this->string = '';
}
//sets everything to it's standard value
function close()
{
$this->__construct();
}
}
?>
voorbeeld.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
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
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
<?php
/*----------------------------------------------
-------------------------------------------------
DONT REMOVE THIS BLOCK!!!
-------------------------------------------------
Copyright
Created by: libia
Created on: 15-09-07 (DD-MM-YY)
-------------------------------------------------
You can use this script,
but you may not call it your script!
-------------------------------------------------
----------------------------------------------*/
error_reporting(E_ALL);
//include the class!
include("stringClass.php");
//and a little example
$string = new String();
$string->prepare("The ? was ? over the ?");
if($string->errno == 0)
{
echo 'There were ' . $string->param_count() . ' params setten<br />';
if($string->errno == 0)
{
$string->bind_param("dog", "jumping", "airplane");
if($string->errno == 0)
{
echo $string->execute() . '<br />';
if($string->errno == 0)
{
$string->bind_param("Wolf", "rolling", "lava");
if($string->errno == 0)
{
echo $string->execute();
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
$string2 = new String();
$string2->prepare("Lol loL ?");
if(trim($string2->errno) == 0)
{
$string2->bind_param($string->execute());
if($string2->errno == 0)
{
echo '<br /><br />' . $string2->execute() . '<br />';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
$string2->close();
//you may use close or free_result + close, it's just what you prefer!
$string->free_result();
$string->close();
?>
/*----------------------------------------------
-------------------------------------------------
DONT REMOVE THIS BLOCK!!!
-------------------------------------------------
Copyright
Created by: libia
Created on: 15-09-07 (DD-MM-YY)
-------------------------------------------------
You can use this script,
but you may not call it your script!
-------------------------------------------------
----------------------------------------------*/
error_reporting(E_ALL);
//include the class!
include("stringClass.php");
//and a little example
$string = new String();
$string->prepare("The ? was ? over the ?");
if($string->errno == 0)
{
echo 'There were ' . $string->param_count() . ' params setten<br />';
if($string->errno == 0)
{
$string->bind_param("dog", "jumping", "airplane");
if($string->errno == 0)
{
echo $string->execute() . '<br />';
if($string->errno == 0)
{
$string->bind_param("Wolf", "rolling", "lava");
if($string->errno == 0)
{
echo $string->execute();
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
$string2 = new String();
$string2->prepare("Lol loL ?");
if(trim($string2->errno) == 0)
{
$string2->bind_param($string->execute());
if($string2->errno == 0)
{
echo '<br /><br />' . $string2->execute() . '<br />';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
$string2->close();
//you may use close or free_result + close, it's just what you prefer!
$string->free_result();
$string->close();
?>