Database Reference
In-Depth Information
print
p
(
escapeHTML
(
"The server version is $version."
));
print
p
(
escapeHTML
(
"The default database is $db."
));
In Ruby, use the
cgi
module
escapeHTML
method to encode the paragraph text, and
then pass it to the
p
method to produce the paragraph tags:
(
now
,
version
,
db
)
=
dbh
.
select_one
(
"SELECT NOW(), VERSION(), DATABASE()"
)
db
=
"NONE"
if
db
.
nil?
cgi
=
CGI
.
new
(
"html4"
)
cgi
.
out
{
cgi
.
p
{
CGI
.
escapeHTML
(
"Local time on the MySQL server is
#{
now
}
."
) }
+
cgi
.
p
{
CGI
.
escapeHTML
(
"The server version is
#{
version
}
."
) }
+
cgi
.
p
{
CGI
.
escapeHTML
(
"The default database is
#{
db
}
."
) }
}
For languages without HTML-tag methods for the required elements, put
<p>
and
</p>
tags around the encoded paragraph text. PHP and Python are examples of this.
PHP:
$sth
=
$dbh
->
query
(
"SELECT NOW(), VERSION(), DATABASE()"
);
list
(
$now
,
$version
,
$db
)
=
$sth
->
fetch
(
PDO
::
FETCH_NUM
);
if
(
$db
===
NULL
)
$db
=
"NONE"
;
$para
=
"Local time on the MySQL server is
$now
."
;
print
(
"<p>"
.
htmlspecialchars
(
$para
)
.
"</p>"
);
$para
=
"The server version is
$version
."
;
print
(
"<p>"
.
htmlspecialchars
(
$para
)
.
"</p>"
);
$para
=
"The default database is
$db
."
;
print
(
"<p>"
.
htmlspecialchars
(
$para
)
.
"</p>"
);
Python:
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"SELECT NOW(), VERSION(), DATABASE()"
)
(
now
,
version
,
db
)
=
cursor
.
fetchone
()
cursor
.
close
()
if
db
is
None
:
db
=
'NONE'
para
=
"Local time on the MySQL server is
%s
."
%
now
print
(
"<p>
%s
</p>"
%
cgi
.
escape
(
para
,
1
))
para
=
"The server version is
%s
."
%
version
print
(
"<p>
%s
</p>"
%
cgi
.
escape
(
para
,
1
))
para
=
"The default database is
%s
."
%
db
print
(
"<p>
%s
</p>"
%
cgi
.
escape
(
para
,
1
))
In JSP, produce the paragraph display using
rowsByIndex
to access the result set row's
columns by numeric index and
<c:out>
to encode and print the text:
<sql:query
dataSource=
"${conn}"
var=
"rs"
>
SELECT NOW(), VERSION(), DATABASE()
</sql:query>
<c:set
var=
"row"
value=
"${rs.rowsByIndex[0]}"
/>