forked from openlink/virtuoso-opensource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.php5
289 lines (218 loc) · 7.13 KB
/
README.php5
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
PHP SAPI module for Virtuoso
============================
This is a SAPI module for PHP 5.x, implemented as a Virtuoso loadable
module.
Building php
------------
To build the plugin, you first need to build a libphp5.so,
configured with ZTS.
Package Version From
------- ------- -----------------------------
php 5.2.10 http://www.php.net/downloads/
In the php source directory, execute something similar to:
./configure \
--prefix=/usr/local/php-5.2.10 \
--enable-maintainer-zts \
--enable-embed=shared \
--with-config-file-path=. \
--with-tsrm-pthreads \
--disable-static \
--disable-cgi \
--disable-ipv6 \
--without-mysql \
--without-pear \
--enable-bcmath=shared \
--enable-calendar \
--enable-dbase=shared \
--enable-dba=shared \
--enable-dom=shared \
--enable-exif=shared \
--enable-ftp=shared \
--enable-gd-native-ttf \
--enable-mbstring=shared \
--enable-pdo \
--enable-shmop=shared \
--enable-soap=shared \
--enable-sockets=shared \
--enable-sysvmsg=shared \
--enable-sysvsem=shared \
--enable-sysvshm=shared \
--enable-wddx=shared \
--enable-xmlreader=shared \
--enable-xmlwriter=shared \
--with-bz2=shared \
--with-curl=shared \
--with-gd=shared \
--with-iodbc=/usr/local/iODBC \
--with-ldap=shared \
--with-mime-magic=shared \
--with-openssl=shared \
--with-pdo-odbc="generic,/usr/local/iODBC,iodbc,-L/usr/local/iODBC/lib,-I/usr/local/iODBC/include" \
--with-sqlite=shared \
--with-xmlrpc=shared \
--with-xsl=shared \
--with-xsl=shared \
--with-zlib \
...
NOTE: The options above require a number of other libraries to be
installed prior to building PHP. On systems where these external
libraries are not available as system libraries you may need
additional configure options to point where certain libraries
are installed.
Next build and install the php packages.
make
make install
In the Virtuoso Open Source directory, execute the following command:
./configure .... --enable-php5=/usr/local/php-5.2.10 ......
or if you configured Virtuoso before in this directory:
./config.nice --enable-php5=/usr/local/php-5.2.10
so the build process knows where to find the necessary PHP header files.
At the end of the configure step, the summary screen should indicate that the
BUILD_OPTS includes "php5". If this is not the case the config.log file should
contain information why configure was unable to locate your php5 installation.
Installation
------------
1. Copy the libphp5.so into same directory where virtuoso installs the
hosting_php5.so plugin e.g.
PREFIX/hosting/libphp5.so.
2. If you have build PHP with shared extensions, you can copy them in
PREFIX/hosting/php
3. Copy the php.ini-recommended from the php distro to the same directory
as your virtuoso.ini e.g.
PREFIX/database/php.ini.
4. Edit your php.ini to change the extensions_dir
setting to the directory where you put your extensions, e.g.:
extensions_dir = PREFIX/hosting/php
3. Register the plugin in your virtuoso.ini:
[Plugins]
..
Load7 = attach, libphp5.so
Load8 = Hosting, hosting_php.so
This will enable the hosting_php plugin to dynamically hook into the
PHP library.
Virtuoso PHP Extensions
=======================
Settings
--------
The Virtuoso php hosting plugin adds the following default settings to the
php.ini file:
[Virtuoso]
virtuoso.logging = On
virtuoso.local_dsn = Local Virtuoso
virtuoso.allow_dba = 0
If virtuoso.logging is On, all php messages are passed back to the
virtuoso logwriter.
The virtuoso.local_dsn is by default set to "Local Virtuoso" which
is the DSN in your odbc.ini file normally associated with your local
virtuoso database.
The virtuoso.allow_dba option rejects the use of the dba uid when using
__virt_internal_dsn().
Functions
---------
__virt_internal_dsn([optional dsn])
Normally when programming a PHP application you have to store datasource,
username and password credentials for making ODBC connections back into
the database. This can be a security risk and requires the administrator
to fix scripts manually when he wants to run a hosted application under
its own sql account.
The __virt_internal_dsn() function returns an ODBC connect string
based on the VSP user that owns the Virtual Directory.
It starts by verifying that the Virtual Directory has been properly setup
and that there is a valid user that has not been disabled and is allowed
to make SQL connections, else it will log a message and return FALSE.
If the user is a system privileged user like dba or dav and the
virtuoso.allow.dba setting is disabled, the function will log a message
and return FALSE.
The function will return an ODBC SQLDriverConnect string using either
the supplied optional_dsn or the virtuoso.local_dsn and the uid/pwd
credentials of the virtual directory in the form:
DSN=use_dsn;UID=uid;PWD=pwd
This string can be used directly with the odbc_connect function in your
script. If you want your PHP application also outside of the virtuoso
hosting environment, you can use it like this:
<?php
//
// ODBC Connection Variables
//
$o_DSN = 'ChangeMe';
$o_UID = 'ChangeMe';
$o_PWD = 'ChangeMe';
if (function_exists ('__virt_internal_dsn')) {
$db = odbc_connect (__virt_internal_dsn(), null, null);
} else {
$db = odbc_connect ($o_DSN, $o_UID, $o_PWD);
}
if (!$db)
error_log ('odbc_connect failed');
// .....
odbc_disconnect ($db);
?>
Here is an example of a Virtuoso SQL script that creates a database
schema and a table, a user that owns the schema and a vhost entry that
can be used for a PHP application.
myapp.sql:
--
-- Sample script
--
--
-- Create the MYAPP schema
--
use MYAPP
;
--
-- Create a user MYADMIN who owns the table in this schema
--
db.dba.user_create (
'MYADMIN', -- Account name
uuid (), -- Random UUID as password
vector ('LOGIN_QUALIFIER', 'MYAPP',
'SQL_ENABLE', 1,
'DAV_ENABLE', 0,
'FULL_NAME', 'MYAPP Administrator'))
;
--
-- Create the tables in this schema
--
create table MYTABLE (
mt_id INTEGER NOT NULL PRIMARY KEY,
mt_value VARCHAR (32)
)
;
--
-- Insert some sample data
--
insert into MYAPP.DBA.MYTABLE VALUES (1, 'Apple');
insert into MYAPP.DBA.MYTABLE VALUES (2, 'Pear');
insert into MYAPP.DBA.MYTABLE VALUES (3, 'Banana');
insert into MYAPP.DBA.MYTABLE VALUES (4, 'Pineapple');
--
-- Add permissions
--
grant all privileges on MYAPP.DBA.MYTABLE to MYADMIN
;
--
-- Create a new virtual path in Virtuoso
--
-- Point to $VIRTUOSO/vsp/testapp on filesystem
--
db.dba.vhost_remove (lpath=>'/myapp');
db.dba.vhost_define (
lpath=>'/myapp',
ppath=>'/testapp',
is_dav=>0,
is_brws=>0,
vsp_user=>'MYADMIN',
def_page=>'myapp.php')
;
--
-- End of sample
--
And the $VIRTUOSO/vsp/testapp/myapp.php:
<?php
$db = odbc_connect (__virt_internal_dsn(), null, null);
if (!$db)
error_log ('odbc_connect failed');
$rs = odbc_exec ($db, 'select * from MYAPP.DBA.MYTEST');
odbc_result_all ($rs);
odbc_close ($db);
?>