more CDATA additions to examples

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@62898 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Hartmut Holzgraefe 2001-11-20 23:58:47 +00:00
parent 1805429b60
commit 91848c237f
12 changed files with 1156 additions and 896 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.23 $ -->
<!-- $Revision: 1.24 $ -->
<reference id="ref.mcrypt">
<title>Mcrypt Encryption Functions</title>
<titleabbrev>mcrypt</titleabbrev>
@ -41,12 +41,14 @@
<example>
<title>Encrypt an input value with TripleDES under 2.2.x in ECB mode</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$key = "this is a very secret key";
$input = "Let us meet at 9 o'clock at the secret place.";
$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, $input, MCRYPT_ENCRYPT);
?&gt;
?>
]]>
</programlisting>
</example>
This example will give you the encrypted data as a string in
@ -58,7 +60,8 @@ $encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, $input, MCRYPT_ENCRYPT);
<example>
<title>Encrypt an input value with TripleDES under 2.4.x in ECB mode</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$key = "this is a very secret key";
$input = "Let us meet at 9 o'clock at the secret place.";
@ -67,7 +70,8 @@ $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
mcrypt_generic_init ($td, $key, $iv);
$encrypted_data = mcrypt_generic ($td, $input);
mcrypt_generic_end ($td);
?&gt;
?>
]]>
</programlisting>
</example>
This example will give you the encrypted data as a string in
@ -397,19 +401,23 @@ mcrypt_generic_end ($td);
<example>
<title><function>mcrypt_get_cipher_name</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$cipher = MCRYPT_TripleDES;
print mcrypt_get_cipher_name ($cipher);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
<para>
The above example will produce:
<programlisting>
<para>
The above example will produce:
<screen>
<![CDATA[
3DES
</programlisting>
]]>
</screen>
</para>
</example>
</para>
</refsect1>
</refentry>
@ -524,11 +532,13 @@ print mcrypt_get_cipher_name ($cipher);
<example>
<title><function>mcrypt_create_iv</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$cipher = MCRYPT_TripleDES;
$block_size = mcrypt_get_block_size ($cipher);
$iv = mcrypt_create_iv ($block_size, MCRYPT_DEV_RANDOM);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -744,7 +754,7 @@ $iv = mcrypt_create_iv ($block_size, MCRYPT_DEV_RANDOM);
<paramdef>int <parameter>mode</parameter></paramdef>
<paramdef>string <parameter>iv</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>mcrypt_ofb</function></funcdef>
@ -804,10 +814,10 @@ $iv = mcrypt_create_iv ($block_size, MCRYPT_DEV_RANDOM);
<funcprototype>
<funcdef>array <function>mcrypt_list_algorithms</function></funcdef>
<paramdef>string
<parameter>
<optional>lib_dir</optional>
</parameter>
</paramdef>
<parameter>
<optional>lib_dir</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
@ -819,26 +829,28 @@ $iv = mcrypt_create_iv ($block_size, MCRYPT_DEV_RANDOM);
<function>mcrypt_list_algorithms</function> takes as optional
parameter a directory which specifies the directory where all
algorithms are located. If not specifies, the value of the
mcrypt.algorithms_dir php.ini directive is used.
mcrypt.algorithms_dir php.ini directive is used.
</para>
<para>
<example>
<title><function>mcrypt_list_algorithms</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$algorithms = mcrypt_list_algorithms ("/usr/local/lib/libmcrypt");
foreach ($algorithms as $cipher) {
echo $cipher."/n";
echo $cipher."/n";
}
?&gt;
?>
]]>
</programlisting>
<para>
The above example will produce a list with all supported
algorithms in the "/usr/local/lib/libmcrypt" directory.
</para>
</example>
</para>
<para>
The above example will produce a list with all supported
algorithms in the "/usr/local/lib/libmcrypt" directory.
</para>
</refsect1>
</refentry>
@ -853,10 +865,10 @@ foreach ($algorithms as $cipher) {
<funcprototype>
<funcdef>array <function>mcrypt_list_modes</function></funcdef>
<paramdef>string
<parameter>
<optional>lib_dir</optional>
</parameter>
</paramdef>
<parameter>
<optional>lib_dir</optional>
</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
<para>
@ -868,28 +880,30 @@ foreach ($algorithms as $cipher) {
<function>mcrypt_list_modes</function> takes as optional
parameter a directory which specifies the directory where all
modes are located. If not specifies, the value of the
mcrypt.modes_dir php.ini directive is used.
mcrypt.modes_dir php.ini directive is used.
</para>
<para>
<example>
<title><function>mcrypt_list_modes</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$modes = mcrypt_list_modes ();
foreach ($modes as $mode) {
echo "$mode &lt;/br&gt;";
echo "$mode <br/>";
}
?&gt;
?>
]]>
</programlisting>
<para>
The above example will produce a list with all supported
algorithms in the default mode directory. If it is not set
with the ini directive mcrypt.modes_dir, the default directory
of mcrypt is used (which is /usr/local/lib/libmcrypt).
</para>
</example>
</para>
<para>
The above example will produce a list with all supported
algorithms in the default mode directory. If it is not set
with the ini directive mcrypt.modes_dir, the default directory
of mcrypt is used (which is /usr/local/lib/libmcrypt).
</para>
</refsect1>
</refentry>
@ -995,7 +1009,8 @@ foreach ($modes as $mode) {
<example>
<title><function>mcrypt_encrypt</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$iv = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$key = "This is a very secret key";
$text = "Meet me at 11 o'clock behind the monument.";
@ -1003,14 +1018,19 @@ echo strlen ($text)."\n";
$crypttext = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
echo strlen ($crypttext)."\n";
?&gt;
?>
]]>
</programlisting>
</example>
The above example will print out:
<programlisting>
<para>
The above example will print out:
<screen>
<![CDATA[
42
64
</programlisting>
]]>
</screen>
</para>
</example>
</para>
</refsect1>
</refentry>
@ -1109,13 +1129,18 @@ echo strlen ($crypttext)."\n";
<example>
<title><function>mcrypt_module_open</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$td = mcrypt_module_open (MCRYPT_DES, "", MCRYPT_MODE_ECB, "/usr/lib/mcrypt-modes");
?&gt;
?>
]]>
</programlisting>
<para>
The above example will try to open the DES cipher
from the default directory and the EBC mode from the directory
<filename>/usr/lib/mcrypt-modes</filename>.
</para>
</example>
The above example will try to open the DES cipher from the default
directory and the EBC mode from the directory /usr/lib/mcrypt-modes.
</para>
</refsect1>
</refentry>
@ -1202,7 +1227,8 @@ $td = mcrypt_module_open (MCRYPT_DES, "", MCRYPT_MODE_ECB, "/usr/lib/mcrypt-mode
<example>
<title><function>mdecrypt_generic</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$iv_size = mcrypt_enc_get_iv_size ($td));
$iv = @mcrypt_create_iv ($iv_size, MCRYPT_RAND);
@ -1216,11 +1242,14 @@ if (strncmp ($p_t, $plain_text, strlen($plain_text)) == 0)
echo "ok";
else
echo "error";
?&gt;
?>
]]>
</programlisting>
<para>
The above example shows how to check if the data before the
encryption is the same as the data after the decryption.
</para>
</example>
The above example shows how to check if the data before the
encryption is the same as the data after the decryption.
</para>
</refsect1>
</refentry>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.18 $ -->
<!-- $Revision: 1.19 $ -->
<reference id="ref.mhash">
<title>Mhash Functions</title>
<titleabbrev>mhash</titleabbrev>
@ -28,20 +28,26 @@
<example>
<title>Compute the MD5 digest and hmac and print it out as hex</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$input = "what do ya want for nothing?";
$hash = mhash (MHASH_MD5, $input);
print "The hash is ".bin2hex ($hash)."\n&lt;br>";
$hash = mhash (MHASH_MD5, $input, "Jefe");
print "The hmac is ".bin2hex ($hash)."\n&lt;br>";
?&gt;
?>
]]>
</programlisting>
</example>
This will produce:
<programlisting>
<para>
This will produce:
<screen>
<![CDATA[
The hash is d03cb659cbf9192dcd066272249f8412
The hmac is 750c783e6ab0b503eaa86e310a5db738
</programlisting>
]]>
</screen>
</para>
</example>
For a complete list of supported hashes, refer to the
documentation of mhash. The general rule is that you can access
the hash algorithm from PHP with MHASH_HASHNAME. For example, to
@ -137,17 +143,23 @@ The hmac is 750c783e6ab0b503eaa86e310a5db738
<example>
<title><function>mhash_get_hash_name</function> Example</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
$hash = MHASH_MD5;
print mhash_get_hash_name ($hash);
?&gt;
?>
]]>
</programlisting>
<para>
The above example will print out:
<screen>
<![CDATA[
MD5
]]>
</screen>
</para>
</example>
The above example will print out:
<programlisting>
MD5
</programlisting>
</para>
</refsect1>
</refentry>
@ -198,16 +210,18 @@ MD5
<example>
<title>Traversing all hashes</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$nr = mhash_count();
for ($i = 0; $i &lt;= $nr; $i++) {
for ($i = 0; $i <= $nr; $i++) {
echo sprintf ("The blocksize of %s is %d\n",
mhash_get_hash_name ($i),
mhash_get_block_size ($i));
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.59 $ -->
<!-- $Revision: 1.60 $ -->
<reference id="ref.misc">
<title>Miscellaneous functions</title>
<titleabbrev>Misc.</titleabbrev>
@ -117,14 +117,16 @@
<example>
<title><function>constant</function> example</title>
<programlisting role="php">
&lt;php
<![CDATA[
<php
define ("MAXSIZE", 100);
echo MAXSIZE;
echo constant("MAXSIZE"); // same thing as the previous line
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -175,7 +177,8 @@ echo constant("MAXSIZE"); // same thing as the previous line
<example>
<title>Defining Constants</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
define ("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.
@ -184,7 +187,8 @@ define ("GREETING", "Hello you.",TRUE);
echo GREETING; // outputs "Hello you."
echo Greeting; // outputs "Hello you."
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -223,11 +227,13 @@ echo Greeting; // outputs "Hello you."
<example>
<title>Checking Constants</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
if (defined("CONSTANT")){ // Note that it should be quoted
echo CONSTANT; //
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -298,23 +304,27 @@ if (defined("CONSTANT")){ // Note that it should be quoted
<function>eval</function> example - simple text merge
</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.&lt;br&gt;';
$str = 'This is a $string with my $name in it.<br>';
echo $str;
eval ("\$str = \"$str\";");
echo $str;
?&gt;
?>
]]>
</programlisting>
</example>
</para>
<para>
The above example will show:
<programlisting>
<screen>
<![CDATA[
This is a $string with my $name in it.
This is a cup with my coffee in it.
</programlisting>
]]>
</screen>
</para>
</example>
</para>
</refsect1>
</refentry>
@ -359,13 +369,15 @@ This is a cup with my coffee in it.
<example>
<title><function>exit</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$filename = '/path/to/data-file';
$file = fopen ($filename, 'r')
or exit("unable to open file ($filename)");
?&gt;
?>
]]>
</programlisting>
<!-- TODO: example with integer exit-statis -->
</example>
@ -418,17 +430,19 @@ $file = fopen ($filename, 'r')
<example>
<title><function>get_browser</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
function list_array ($array) {
while (list ($key, $value) = each ($array)) {
$str .= "&lt;b&gt;$key:&lt;/b&gt; $value&lt;br&gt;\n";
$str .= "<b>$key:</b> $value<br>\n";
}
return $str;
}
echo "$HTTP_USER_AGENT&lt;hr&gt;\n";
echo "$HTTP_USER_AGENT<hr>\n";
$browser = get_browser();
echo list_array ((array) $browser);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -436,26 +450,28 @@ echo list_array ((array) $browser);
The output of the above script would look something like this:
</simpara>
<programlisting>
Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)&lt;hr&gt;
&lt;b&gt;browser_name_pattern:&lt;/b&gt; Mozilla/4\.5.*&lt;br&gt;
&lt;b&gt;parent:&lt;/b&gt; Netscape 4.0&lt;br&gt;
&lt;b&gt;platform:&lt;/b&gt; Unknown&lt;br&gt;
&lt;b&gt;majorver:&lt;/b&gt; 4&lt;br&gt;
&lt;b&gt;minorver:&lt;/b&gt; 5&lt;br&gt;
&lt;b&gt;browser:&lt;/b&gt; Netscape&lt;br&gt;
&lt;b&gt;version:&lt;/b&gt; 4&lt;br&gt;
&lt;b&gt;frames:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;tables:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;cookies:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;backgroundsounds:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;vbscript:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;javascript:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;javaapplets:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;activexcontrols:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;beta:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;crawler:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;authenticodeupdate:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;msn:&lt;/b&gt; &lt;br&gt;
<![CDATA[
Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)<hr>
<b>browser_name_pattern:</b> Mozilla/4\.5.*<br>
<b>parent:</b> Netscape 4.0<br>
<b>platform:</b> Unknown<br>
<b>majorver:</b> 4<br>
<b>minorver:</b> 5<br>
<b>browser:</b> Netscape<br>
<b>version:</b> 4<br>
<b>frames:</b> 1<br>
<b>tables:</b> 1<br>
<b>cookies:</b> 1<br>
<b>backgroundsounds:</b> <br>
<b>vbscript:</b> <br>
<b>javascript:</b> 1<br>
<b>javaapplets:</b> 1<br>
<b>activexcontrols:</b> <br>
<b>beta:</b> <br>
<b>crawler:</b> <br>
<b>authenticodeupdate:</b> <br>
<b>msn:</b> <br>
]]>
</programlisting>
<simpara>
In order for this to work, your <link
@ -506,7 +522,7 @@ Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)&lt;hr&gt;
<title>Creating a source highlighting URL</title>
<simpara>
To setup a URL that can code hightlight any script that you pass to
it, we will make use of the &quot;ForceType&quot; directive in
it, we will make use of the "ForceType" directive in
Apache to generate a nice URL pattern, and use the
function <function>highlight_file</function> to show a nice looking
code list.
@ -516,50 +532,57 @@ Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)&lt;hr&gt;
</simpara>
<para>
<informalexample>
<programlisting>
&lt;Location /source&gt;
<programlisting>
<![CDATA[
<Location /source>
ForceType application/x-httpd-php
&lt;/Location&gt;
</programlisting></informalexample>
</Location>
]]>
</programlisting>
</informalexample>
</para>
<simpara>
And then make a file named &quot;source&quot; and put it in your
And then make a file named "source" and put it in your
web root directory.
</simpara>
<para>
<programlisting role="php">
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Source Display&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY BGCOLOR=&quot;white&quot;&gt;
&lt;?php
$script = getenv (&quot;PATH_TRANSLATED&quot;);
<![CDATA[
<HTML>
<HEAD>
<TITLE>Source Display</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<?php
$script = getenv ("PATH_TRANSLATED");
if(!$script) {
echo &quot;&lt;BR&gt;&lt;B&gt;ERROR: Script Name needed&lt;/B&gt;&lt;BR&gt;&quot;;
echo "<BR><B>ERROR: Script Name needed</B><BR>";
} else {
if (ereg(&quot;(\.php|\.inc)$&quot;,$script)) {
echo &quot;&lt;H1&gt;Source of: $PATH_INFO&lt;/H1&gt;\n&lt;HR&gt;\n&quot;;
if (ereg("(\.php|\.inc)$",$script)) {
echo "<H1>Source of: $PATH_INFO</H1>\n<HR>\n";
highlight_file($script);
} else {
echo &quot;&lt;H1&gt;ERROR: Only PHP or include script names are allowed&lt;/H1&gt;&quot;;
echo "<H1>ERROR: Only PHP or include script names are allowed</H1>";
}
}
echo &quot;&lt;HR&gt;Processed: &quot;.date(&quot;Y/M/d H:i:s&quot;,time());
?&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
echo "<HR>Processed: ".date("Y/M/d H:i:s",time());
?>
</BODY>
</HTML>
]]>
</programlisting>
</para>
<simpara>
Then you can use an URL like the one below to display a colorized
version of a script located in &quot;/path/to/script.php&quot;
version of a script located in "/path/to/script.php"
in your web site.
</simpara>
<para>
<informalexample>
<programlisting>
<![CDATA[
http://your.server.com/source/path/to/script.php
]]>
</programlisting>
</informalexample>
</para>
@ -821,7 +844,9 @@ http://your.server.com/source/path/to/script.php
<example>
<title><function>pack</function> format string</title>
<programlisting role="php">
<![CDATA[
$binarydata = pack ("nvc*", 0x1234, 0x5678, 65, 66);
]]>
</programlisting>
<para>
The resulting binary string will be 6 bytes long and contain
@ -954,8 +979,10 @@ $binarydata = pack ("nvc*", 0x1234, 0x5678, 65, 66);
it is recommended that you use something along the lines of
<informalexample>
<programlisting role="php">
<![CDATA[
$token = md5 (uniqid ("")); // no random portion
$better_token = md5 (uniqid (rand())); // better, difficult to guess
]]>
</programlisting>
</informalexample>
</para>
@ -993,7 +1020,9 @@ $better_token = md5 (uniqid (rand())); // better, difficult to guess
<example>
<title><function>unpack</function> format string</title>
<programlisting role="php">
<![CDATA[
$array = unpack ("c2chars/nint", $binarydata);
]]>
</programlisting>
<para>
The resulting array will contain the entries "chars1",

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.28 $ -->
<!-- $Revision: 1.29 $ -->
<reference id="ref.mnogo">
<title>mnoGoSearch Functions</title>
<titleabbrev>mnoGoSearch</titleabbrev>
@ -228,9 +228,11 @@
<simpara>Example:</simpara>
<informalexample>
<programlisting role="C">
if (Udm_Api_Version() &gt;= 30111) {
print "Total number of urls in database: ".Udm_Get_Doc_Count($udm)."&lt;br&gt;\n";
<![CDATA[
if (Udm_Api_Version() >= 30111) {
print "Total number of urls in database: ".Udm_Get_Doc_Count($udm)."<br>\n";
}
]]>
</programlisting>
</informalexample>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.18 $ -->
<!-- $Revision: 1.19 $ -->
<reference id="ref.msql">
<title>mSQL functions</title>
<titleabbrev>mSQL</titleabbrev>
@ -1125,16 +1125,18 @@
<example>
<title><function>msql_tablename</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
msql_connect ("localhost");
$result = msql_list_tables ("wisconsin");
$i = 0;
while ($i &lt; msql_numrows ($result)) {
while ($i < msql_numrows ($result)) {
$tb_names[$i] = msql_tablename ($result, $i);
echo $tb_names[$i] . "&lt;BR>";
echo $tb_names[$i] . "<BR>";
$i++;
}
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.21 $ -->
<!-- $Revision: 1.22 $ -->
<reference id="ref.mssql">
<title>Microsoft SQL Server functions</title>
<titleabbrev>MS SQL Server</titleabbrev>
@ -497,7 +497,8 @@
<example>
<title><function>mssql_next_result</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$link = mssql_connect ("localhost", "userid", "secret");
mssql_select_db("MyDB", $link);
$SQL = "Select * from table1 select * from table2";
@ -508,7 +509,8 @@
} while (mssql_next_result($rs));
mssql_free_result($rs);
mssql_close ($link);
?&gt;
?>
]]>
</programlisting>
</example>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.75 $ -->
<!-- $Revision: 1.76 $ -->
<reference id="ref.mysql">
<title>MySQL Functions</title>
<titleabbrev>MySQL</titleabbrev>
@ -215,12 +215,14 @@ mysql_close($link);
<example>
<title>MySQL close example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$link = mysql_connect ("kraemer", "marliesle", "secret")
or die ("Could not connect");
print ("Connected successfully");
mysql_close ($link);
?&gt;
?>
]]>
</programlisting>
</example>
<para>
@ -300,12 +302,14 @@ mysql_close($link);
<example>
<title>MySQL connect example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$link = mysql_connect ("localhost", "username", "secret")
or die ("Could not connect");
print ("Connected successfully");
mysql_close ($link);
?&gt;
?>
]]>
</programlisting>
</example>
<para> See also
@ -344,7 +348,8 @@ mysql_close($link);
<example>
<title>MySQL create database example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$link = mysql_pconnect ("kron", "jutta", "geheim")
or die ("Could not connect");
if (mysql_create_db ("my_db")) {
@ -352,7 +357,8 @@ mysql_close($link);
} else {
printf ("Error creating database: %s\n", mysql_error ());
}
?&gt;
?>
]]>
</programlisting>
</example>
<para>
@ -394,7 +400,8 @@ mysql_close($link);
<example>
<title>MySQL data seek example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
&<?php
$link = mysql_pconnect ("kron", "jutta", "geheim")
or die ("Could not connect");
@ -416,11 +423,12 @@ mysql_close($link);
if(!($row = mysql_fetch_object ($result)))
continue;
echo ("$row-&gt;last_name $row-&gt;first_name&lt;BR&gt;\n";
echo "$row->last_name $row->first_name<br />\n";
}
mysql_free_result ($result);
?&gt;
?>
]]>
</programlisting>
</example>
</refsect1>
@ -461,7 +469,8 @@ mysql_close($link);
<example>
<title><function>mysql_db_name</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
error_reporting(E_ALL);
mysql_connect('dbhost', 'username', 'password');
@ -469,11 +478,12 @@ $db_list = mysql_list_dbs();
$i = 0;
$cnt = mysql_num_rows($db_list);
while ($i &lt; $cnt) {
while ($i < $cnt) {
echo mysql_db_name($db_list, $i) . "\n";
$i++;
}
?&gt;
?>
]]>
</programlisting>
</example>
<para>
@ -597,18 +607,20 @@ while ($i &lt; $cnt) {
error code from the most recently executed MySQL function (not
including <function>mysql_error</function> and
<function>mysql_errno</function>), so if you want to use it,
make sure you check the value before calling another mySQL
function.
make sure you check the value before calling another mySQL
function.
<informalexample>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
mysql_connect("marliesle");
echo mysql_errno().": ".mysql_error()."&lt;BR>";
echo mysql_errno().": ".mysql_error()."<BR>";
mysql_select_db("nonexistentdb");
echo mysql_errno().": ".mysql_error()."&lt;BR>";
echo mysql_errno().": ".mysql_error()."<BR>";
$conn = mysql_query("SELECT * FROM nonexistenttable");
echo mysql_errno().": ".mysql_error()."&lt;BR>";
?&gt;
echo mysql_errno().": ".mysql_error()."<BR>";
?>
]]>
</programlisting>
</informalexample>
</para>
@ -652,14 +664,16 @@ echo mysql_errno().": ".mysql_error()."&lt;BR>";
sure you check the value before calling another MySQL function.
<informalexample>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
mysql_connect("marliesle");
echo mysql_errno().": ".mysql_error()."&lt;BR>";
echo mysql_errno().": ".mysql_error()."<BR>";
mysql_select_db("nonexistentdb");
echo mysql_errno().": ".mysql_error()."&lt;BR>";
echo mysql_errno().": ".mysql_error()."<BR>";
$conn = mysql_query("SELECT * FROM nonexistenttable");
echo mysql_errno().": ".mysql_error()."&lt;BR>";
?&gt;
echo mysql_errno().": ".mysql_error()."<BR>";
?>
]]>
</programlisting>
</informalexample>
</para>
@ -734,8 +748,10 @@ echo mysql_errno().": ".mysql_error()."&lt;BR>";
access the contents with the original column name (by using
<literal>'field'</literal> in this example).
<informalexample>
<programlisting>
<programlisting role="sql">
<![CDATA[
select tone.field as foo ttwo.field as bar from tone, ttwo
]]>
</programlisting>
</informalexample>
</para>
@ -768,17 +784,19 @@ select tone.field as foo ttwo.field as bar from tone, ttwo
<example>
<title><function>mysql_fetch_array</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
mysql_connect ($host, $user, $password);
$result = mysql_db_query ("database","select user_id, fullname from table");
while ($row = mysql_fetch_array ($result)) {
echo "user_id: ".$row["user_id"]."&lt;br>\n";
echo "user_id: ".$row[0]."&lt;br>\n";
echo "fullname: ".$row["fullname"]."&lt;br>\n";
echo "fullname: ".$row[1]."&lt;br>\n";
echo "user_id: ".$row["user_id"]."<br>\n";
echo "user_id: ".$row[0]."<br>\n";
echo "fullname: ".$row["fullname"]."<br>\n";
echo "fullname: ".$row[1]."<br>\n";
}
mysql_free_result ($result);
?&gt;
?>
]]>
</programlisting>
</example>
</refsect1>
@ -834,7 +852,8 @@ mysql_free_result ($result);
<example>
<title><function>mysql_fetch_assoc</function></title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
mysql_connect ($host, $user, $password);
$result = mysql_db_query ("database","select * from table");
while ($row = mysql_fetch_assoc ($result)) {
@ -842,7 +861,8 @@ while ($row = mysql_fetch_assoc ($result)) {
echo $row["fullname"];
}
mysql_free_result ($result);
?&gt;
?>
]]>
</programlisting>
</example>
</refsect1>
@ -945,20 +965,21 @@ mysql_free_result ($result);
<example>
<title><function>mysql_fetch_field</function></title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
mysql_connect ($host, $user, $password)
or die ("Could not connect");
$result = mysql_db_query ("database", "select * from table")
or die ("Query failed");
# get column metadata
$i = 0;
while ($i &lt; mysql_num_fields ($result)) {
echo "Information for column $i:&lt;BR>\n";
while ($i < mysql_num_fields ($result)) {
echo "Information for column $i:<BR>\n";
$meta = mysql_fetch_field ($result);
if (!$meta) {
echo "No information available&lt;BR>\n";
echo "No information available<BR>\n";
}
echo "&lt;PRE>
echo "<PRE>
blob: $meta->blob
max_length: $meta->max_length
multiple_key: $meta->multiple_key
@ -971,11 +992,12 @@ type: $meta->type
unique_key: $meta->unique_key
unsigned: $meta->unsigned
zerofill: $meta->zerofill
&lt;/PRE>";
</PRE>";
$i++;
}
mysql_free_result ($result);
?&gt;
?>
]]>
</programlisting>
</example>
<para>
@ -1062,7 +1084,8 @@ mysql_free_result ($result);
<example>
<title><function>mysql_fetch_object</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
mysql_connect ($host, $user, $password);
$result = mysql_db_query ("database", "select * from table");
while ($row = mysql_fetch_object ($result)) {
@ -1070,7 +1093,8 @@ while ($row = mysql_fetch_object ($result)) {
echo $row->fullname;
}
mysql_free_result ($result);
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -1188,6 +1212,7 @@ mysql_free_result ($result);
<example>
<title><function>mysql_field_name</function> example</title>
<programlisting role="php">
<![CDATA[
// The users table consists of three fields:
// user_id
// username
@ -1197,17 +1222,18 @@ $res = mysql_db_query("users", "select * from users", $link);
echo mysql_field_name($res, 0) . "\n";
echo mysql_field_name($res, 2);
]]>
</programlisting>
</example>
</para>
<para>
The above example would produce the following output:
<informalexample>
<programlisting>
<para>
The above example would produce the following output:
<screen>
<![CDATA[
user_id
password
</programlisting>
</informalexample>
]]>
</screen>
</para>
</example>
</para>
<para>
For downwards compatibility <function>mysql_fieldname</function>
@ -1324,7 +1350,8 @@ password
<example>
<title>MySQL field types</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
mysql_connect ("localhost:3306");
mysql_select_db ("wisconsin");
@ -1333,19 +1360,20 @@ $fields = mysql_num_fields ($result);
$rows = mysql_num_rows ($result);
$i = 0;
$table = mysql_field_table ($result, $i);
echo "Your '".$table."' table has ".$fields." fields and ".$rows." records &lt;BR>";
echo "The table has the following fields &lt;BR>";
while ($i &lt; $fields) {
echo "Your '".$table."' table has ".$fields." fields and ".$rows." records <BR>";
echo "The table has the following fields <BR>";
while ($i < $fields) {
$type = mysql_field_type ($result, $i);
$name = mysql_field_name ($result, $i);
$len = mysql_field_len ($result, $i);
$flags = mysql_field_flags ($result, $i);
echo $type." ".$name." ".$len." ".$flags."&lt;BR>";
echo $type." ".$name." ".$len." ".$flags."<BR>";
$i++;
}
mysql_close();
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -1475,25 +1503,29 @@ mysql_close();
<example>
<title><function>mysql_list_dbs</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$link = mysql_connect('localhost', 'myname', 'secret');
$db_list = mysql_list_dbs($link);
while ($row = mysql_fetch_object($db_list)) {
echo $row->Database . "\n";
}
?>
]]>
</programlisting>
</example>
</para>
<para>
The above example would produce the following output:
<informalexample>
<programlisting>
<para>
The above example would produce the following output:
<screen>
<![CDATA[
database1
database2
database3
...
</programlisting>
</informalexample>
]]>
</screen>
</para>
</example>
</para>
<note>
<para>
@ -1543,27 +1575,30 @@ database3
<example>
<title><function>mysql_list_fields</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$link = mysql_connect('localhost', 'myname', 'secret');
$fields = mysql_list_fields("database1", "table1", $link);
$columns = mysql_num_fields($fields);
for ($i = 0; $i &lt; $columns; $i++) {
for ($i = 0; $i < $columns; $i++) {
echo mysql_field_name($fields, $i) . "\n";;
}
]]>
</programlisting>
</example>
</para>
<para>
The above example would produce the following output:
<informalexample>
<programlisting>
<para>
The above example would produce the following output:
<screen>
<![CDATA[
field1
field2
field3
...
</programlisting>
</informalexample>
]]>
</screen>
</para>
</example>
</para>
<para>
For downward compatibility <function>mysql_listfields</function>
@ -1660,7 +1695,8 @@ field3
<example>
<title><function>mysql_num_rows</function> example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$link = mysql_connect("localhost", "username", "password");
mysql_select_db("database", $link);
@ -1670,7 +1706,8 @@ $num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -1818,10 +1855,12 @@ echo "$num_rows Rows\n";
<example>
<title><function>mysql_query</function></title>
<programlisting role="php">
&lt;?php
<![CDATA[
<php
$result = mysql_query ("SELECT * WHERE 1=1")
or die ("Invalid query");
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -1833,10 +1872,12 @@ $result = mysql_query ("SELECT * WHERE 1=1")
<example>
<title><function>mysql_query</function></title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$result = mysql_query ("SELECT my_col FROM my_tbl")
or die ("Invalid query");
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -2044,16 +2085,18 @@ $result = mysql_query ("SELECT my_col FROM my_tbl")
<example>
<title><function>mysql_tablename</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
mysql_connect ("localhost:3306");
$result = mysql_list_tables ("wisconsin");
$i = 0;
while ($i &lt; mysql_num_rows ($result)) {
while ($i < mysql_num_rows ($result)) {
$tb_names[$i] = mysql_tablename ($result, $i);
echo $tb_names[$i] . "&lt;BR>";
echo $tb_names[$i] . "<BR>";
$i++;
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.44 $ -->
<!-- $Revision: 1.45 $ -->
<reference id="ref.network">
<title>Network Functions</title>
<titleabbrev>Network</titleabbrev>
@ -214,9 +214,11 @@
<example>
<title><function>fsockopen</function> Example</title>
<programlisting role="php">
<![CDATA[
<?php
$fp = fsockopen ("www.php.net", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)&lt;br&gt;\n";
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
while (!feof($fp)) {
@ -224,6 +226,8 @@ if (!$fp) {
}
fclose ($fp);
}
?>
]]>
</programlisting>
</example>
The example below shows how to retrieve the day and time
@ -231,16 +235,18 @@ if (!$fp) {
<example>
<title>Using UDP connection</title>
<programlisting role="php">
<![CDATA[
&lt;?php
$fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr&lt;br&gt;\n";
echo "ERROR: $errno - $errstr<br>\n";
} else {
fwrite($fp,"\n");
echo fread($fp, 26);
fclose($fp);
}
?&gt;
?>
]]>
</programlisting>
</example>
<note>
@ -512,12 +518,14 @@ if (!$fp) {
<example>
<title><function>ip2long</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$ip = gethostbyname("www.php.net");
$out = "The following URLs are equivalent:&lt;br&gt;\n";
$out .= "http://www.php.net/, http://".$ip."/, and http://".sprintf("%u",ip2long($ip))."/&lt;br&gt;\n";
$out = "The following URLs are equivalent:<br>\n";
$out .= "http://www.php.net/, http://".$ip."/, and http://".sprintf("%u",ip2long($ip))."/<br>\n";
echo $out;
?&gt;
?>
]]>
</programlisting>
</example>
<note>
@ -533,11 +541,13 @@ echo $out;
<example>
<title>Displaying an IP address</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$ip = gethostbyname("www.php.net");
printf("%u\n", ip2long($ip));
echo $out;
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -868,7 +878,8 @@ echo $out;
<example>
<title><function>socket_set_timeout</function> Example</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$fp = fsockopen("www.php.net", 80);
if(!$fp) {
echo "Unable to open\n";
@ -881,7 +892,8 @@ if(!$fp) {
fclose($fp);
print $res;
}
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -970,12 +982,13 @@ if(!$fp) {
<example>
<title>Using <function>syslog</function></title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
define_syslog_variables();
// open syslog, include the process ID and also send
// the log to standard error, and use a user defined
// logging mechanism
openlog(&quot;myScripLog&quot;, LOG_PID | LOG_PERROR, LOG_LOCAL0);
openlog("myScripLog", LOG_PID | LOG_PERROR, LOG_LOCAL0);
// some code
@ -984,12 +997,13 @@ if (authorized_client()) {
} else {
// unauthorized client!
// log the attempt
$access = date(&quot;Y/m/d H:i:s&quot;);
syslog(LOG_WARNING,&quot;Unauthorized client: $access $REMOTE_ADDR ($HTTP_USER_AGENT)&quot;);
$access = date("Y/m/d H:i:s");
syslog(LOG_WARNING,"Unauthorized client: $access $REMOTE_ADDR ($HTTP_USER_AGENT)");
}
closelog();
?&gt;
?>
]]>
</programlisting>
</example>
For information on setting up a user defined log handler, see the

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.17 $ -->
<!-- $Revision: 1.18 $ -->
<reference id="ref.nis">
<title>YP/NIS Functions</title>
<titleabbrev>YP/NIS</titleabbrev>
@ -47,10 +47,12 @@
<example>
<title>Example for the default domain</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$domain = yp_get_default_domain();
echo "Default NIS domain is: " . $domain;
?>
]]>
</programlisting>
</example>
</para>
@ -85,10 +87,12 @@ echo "Default NIS domain is: " . $domain;
<example>
<title>Example for the NIS order</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$number = yp_order($domain,$mapname);
echo "Order number for this map is: " . $number;
?>
]]>
</programlisting>
</example>
</para>
@ -126,10 +130,12 @@ echo "Default NIS domain is: " . $domain;
<example>
<title>Example for the NIS master</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$number = yp_master ($domain, $mapname);
echo "Master for this map is: " . $master;
?>
]]>
</programlisting>
</example>
</para>
@ -166,10 +172,12 @@ echo "Master for this map is: " . $master;
<example>
<title>Example for NIS match</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$entry = yp_match ($domain, "passwd.byname", "joe");
echo "Matched entry is: " . $entry;
?>
]]>
</programlisting>
</example>
</para>
@ -211,12 +219,14 @@ echo "Matched entry is: " . $entry;
<example>
<title>Example for the NIS first</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$entry = yp_first($domain, "passwd.byname");
$key = $entry ["key"];
$value = $entry ["value"];
echo "First entry in this map has key " . $key . " and value " . $value;
?>
]]>
</programlisting>
</example>
</para>
@ -254,7 +264,8 @@ echo "First entry in this map has key " . $key . " and value " . $value;
<example>
<title>Example for NIS next</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
$entry = yp_next ($domain, "passwd.byname", "joe");
if (!$entry) {
@ -267,6 +278,7 @@ $key = key ($entry);
echo "The next entry after joe has key " . $key
. " and value " . $entry[$key];
?>
]]>
</programlisting>
</example>
</para>
@ -358,9 +370,11 @@ echo "The next entry after joe has key " . $key
<example>
<title>Example for NIS errors</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
echo "Error: " . yp_err_string();
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.34 $ -->
<!-- $Revision: 1.35 $ -->
<reference id="ref.oci8">
<title>Oracle 8 functions</title>
<titleabbrev>OCI8</titleabbrev>
@ -65,7 +65,8 @@
</para>
<para>
<informalexample>
<programlisting>
<screen>
<![CDATA[
# ldd /www/apache/bin/httpd
libpthread.so.0 => /lib/libpthread.so.0 (0x4001c000)
libm.so.6 => /lib/libm.so.6 (0x4002f000)
@ -73,7 +74,8 @@
libdl.so.2 => /lib/libdl.so.2 (0x4007a000)
libc.so.6 => /lib/libc.so.6 (0x4007e000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
</programlisting>
]]>
</screen>
</informalexample>
</para>
<para>
@ -81,13 +83,15 @@
</para>
<para>
<informalexample>
<programlisting>
<screen>
<![CDATA[
# cd /usr/src/apache_1.3.xx
# make clean
# LIBS=-lpthread ./config.status
# make
# make install
</programlisting>
]]>
</screen>
</informalexample>
</para>
</note>
@ -95,7 +99,8 @@
<example>
<title>OCI Hints</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
// by sergo@bacup.ru
// Use option: OCI_DEFAULT for execute command to delay execution
@ -104,7 +109,7 @@ OCIExecute($stmt, OCI_DEFAULT);
// for retrieve data use (after fetch):
$result = OCIResult($stmt, $n);
if (is_object ($result)) $result = $result-&gt;load();
if (is_object ($result)) $result = $result->load();
// For INSERT or UPDATE statement use:
@ -112,12 +117,12 @@ $sql = "insert into table (field1, field2) values (field1 = 'value',
field2 = empty_clob()) returning field2 into :field2";
OCIParse($conn, $sql);
$clob = OCINewDescriptor($conn, OCI_D_LOB);
OCIBindByName ($stmt, ":field2", &amp;$clob, -1, OCI_B_CLOB);
OCIBindByName ($stmt, ":field2", &$clob, -1, OCI_B_CLOB);
OCIExecute($stmt, OCI_DEFAULT);
$clob-&gt;save ("some text");
$clob->save ("some text");
OCICommit($conn);
?&gt;
?>
</programlisting>
</example>
</para>
@ -127,7 +132,8 @@ OCICommit($conn);
<example>
<title>Using Stored Procedures</title>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
// by webmaster@remoterealty.com
$sth = OCIParse ( $dbh, "begin sp_newaddress( :address_id, '$firstname',
'$lastname', '$company', '$address1', '$address2', '$city', '$state',
@ -141,7 +147,8 @@ $sth = OCIParse ( $dbh, "begin sp_newaddress( :address_id, '$firstname',
OCIBindByName ( $sth, ":error_code", $errorcode, 10 );
OCIExecute ( $sth );
?&gt;
?>
]]>
</programlisting>
</example>
</para>
@ -184,7 +191,8 @@ $sth = OCIParse ( $dbh, "begin sp_newaddress( :address_id, '$firstname',
<example>
<title>OCIDefineByName</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
/* OCIDefineByPos example thies@thieso.net (980219) */
$conn = OCILogon("scott","tiger");
@ -206,6 +214,7 @@ while (OCIFetch($stmt)) {
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
]]>
</programlisting>
</example>
</refsect1>
@ -256,7 +265,8 @@ OCILogoff($conn);
<example>
<title>OCIDefineByName</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
/* OCIBindByPos example thies@thieso.net (980221)
inserts 3 records into emp, and uses the ROWID for updating the
records just after the insert.
@ -306,6 +316,7 @@ OCIFreeStatement($stmt);
OCILogoff($conn);
?>
]]>
</programlisting>
</example>
<warning>
@ -357,8 +368,9 @@ OCILogoff($conn);
<example>
<title>OCILogon</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;PRE>";
<![CDATA[
<?php
print "<HTML><PRE>";
$db = "";
$c1 = ocilogon("scott","tiger",$db);
@ -404,7 +416,7 @@ function select_data($conn)
ociexecute($stmt,OCI_DEFAULT);
echo $conn."----selecting\n\n";
while (ocifetch($stmt))
echo $conn." &lt;".ociresult($stmt,"TEST").">\n\n";
echo $conn." <".ociresult($stmt,"TEST").">\n\n";
echo $conn."----done\n\n";
}
@ -435,8 +447,12 @@ select_data($c2); // no rows returned
drop_table($c1);
print "&lt;/PRE>&lt;/HTML>";
?></programlisting></example></para>
print "</PRE></HTML>";
?>
]]>
</programlisting>
</example>
</para>
<simpara>
See also <function>OCIPLogon</function> and
<function>OCINLogon</function>.</simpara>
@ -518,8 +534,9 @@ print "&lt;/PRE>&lt;/HTML>";
<example>
<title>OCINLogon</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;PRE>";
<![CDATA[
<?php
print "<HTML><PRE>";
$db = "";
$c1 = ocilogon("scott","tiger",$db);
@ -566,7 +583,7 @@ function select_data($conn)
ociexecute($stmt,OCI_DEFAULT);
echo $conn."----selecting\n\n";
while (ocifetch($stmt))
echo $conn." &lt;".ociresult($stmt,"TEST").">\n\n";
echo $conn." <".ociresult($stmt,"TEST").">\n\n";
echo $conn."----done\n\n";
}
@ -596,8 +613,11 @@ select_data($c2);
drop_table($c1);
print "&lt;/PRE>&lt;/HTML>";
?></programlisting></example>
print "</PRE></HTML>";
?>
]]>
</programlisting>
</example>
</para>
<simpara>
See also <function>OCILogon</function> and
@ -721,7 +741,8 @@ print "&lt;/PRE>&lt;/HTML>";
<example>
<title>OCINewDescriptor</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
/* This script is designed to be called from a HTML form.
* It expects $user, $password, $table, $where, and $commitsize
* to be passed in from the form. The script then deletes
@ -731,12 +752,12 @@ print "&lt;/PRE>&lt;/HTML>";
$conn = OCILogon($user, $password);
$stmt = OCIParse($conn,"select rowid from $table $where");
$rowid = OCINewDescriptor($conn,OCI_D_ROWID);
OCIDefineByName($stmt,"ROWID",&amp;$rowid);
OCIDefineByName($stmt,"ROWID",&$rowid);
OCIExecute($stmt);
while ( OCIFetch($stmt) ) {
$nrows = OCIRowCount($stmt);
$delete = OCIParse($conn,"delete from $table where ROWID = :rid");
OCIBindByName($delete,":rid",&amp;$rowid,-1,OCI_B_ROWID);
OCIBindByName($delete,":rid",&$rowid,-1,OCI_B_ROWID);
OCIExecute($delete);
print "$nrows\n";
if ( ($nrows % $commitsize) == 0 ) {
@ -748,29 +769,31 @@ print "&lt;/PRE>&lt;/HTML>";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
]]>
</programlisting>
<programlisting>
&lt;?php
<![CDATA[
<?php
/* This script demonstrates file upload to LOB columns
* The formfield used for this example looks like this
* &lt;form action="upload.php3" method="post" enctype="multipart/form-data">
* &lt;input type="file" name="lob_upload">
* <form action="upload.php3" method="post" enctype="multipart/form-data">
* <input type="file" name="lob_upload">
* ...
*/
if(!isset($lob_upload) || $lob_upload == 'none'){
?>
&lt;form action="upload.php3" method="post" enctype="multipart/form-data">
Upload file: &lt;input type="file" name="lob_upload">&lt;br>
&lt;input type="submit" value="Upload"> - &lt;input type="reset">
&lt;/form>
&lt;?php
<form action="upload.php3" method="post" enctype="multipart/form-data">
Upload file: <input type="file" name="lob_upload"><br>
<input type="submit" value="Upload"> - <input type="reset">
</form>
<?php
} else {
// $lob_upload contains the temporary filename of the uploaded file
$conn = OCILogon($user, $password);
$lob = OCINewDescriptor($conn, OCI_D_LOB);
$stmt = OCIParse($conn,"insert into $table (id, the_blob)
values(my_seq.NEXTVAL, EMPTY_BLOB()) returning the_blob into :the_blob");
OCIBindByName($stmt, ':the_blob', &amp;$lob, -1, OCI_B_BLOB);
OCIBindByName($stmt, ':the_blob', &$lob, -1, OCI_B_BLOB);
OCIExecute($stmt, OCI_DEFAULT);
if($lob->savefile($lob_upload)){
OCICommit($conn);
@ -783,12 +806,14 @@ Upload file: &lt;input type="file" name="lob_upload">&lt;br>
OCILogoff($conn);
}
?>
]]>
</programlisting>
</example>
<example>
<title>OCINewDescriptor</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
/* Calling PL/SQL stored procedures which contain clobs as input
* parameters (PHP 4 >= 4.0.6).
* Example PL/SQL stored procedure signature is:
@ -813,6 +838,7 @@ Upload file: &lt;input type="file" name="lob_upload">&lt;br>
$clob->free();
OCIFreeStatement($stmt);
?>
]]>
</programlisting>
</example>
</refsect1>
@ -839,24 +865,28 @@ Upload file: &lt;input type="file" name="lob_upload">&lt;br>
<example>
<title>OCIRowCount</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;PRE>";
<![CDATA[
<?php
print "<HTML><PRE>";
$conn = OCILogon("scott","tiger");
$stmt = OCIParse($conn,"create table emp2 as select * from emp");
OCIExecute($stmt);
print OCIRowCount($stmt) . " rows inserted.&lt;BR>";
print OCIRowCount($stmt) . " rows inserted.<BR>";
OCIFreeStatement($stmt);
$stmt = OCIParse($conn,"delete from emp2");
OCIExecute($stmt);
print OCIRowCount($stmt) . " rows deleted.&lt;BR>";
print OCIRowCount($stmt) . " rows deleted.<BR>";
OCICommit($conn);
OCIFreeStatement($stmt);
$stmt = OCIParse($conn,"drop table emp2");
OCIExecute($stmt);
OCIFreeStatement($stmt);
OCILogOff($conn);
print "&lt;/PRE>&lt;/HTML>";
?> </programlisting></example>
print "</PRE></HTML>";
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
@ -883,15 +913,16 @@ Upload file: &lt;input type="file" name="lob_upload">&lt;br>
<example>
<title>OCINumCols</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;PRE>\n";
<![CDATA[
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("scott", "tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
while ( OCIFetch($stmt) ) {
print "\n";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i &lt;= $ncols; $i++ ) {
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_value = OCIResult($stmt,$i);
print $column_name . ': ' . $column_value . "\n";
@ -900,9 +931,10 @@ Upload file: &lt;input type="file" name="lob_upload">&lt;br>
}
OCIFreeStatement($stmt);
OCILogoff($conn);
print "&lt;/PRE>";
print "&lt;/HTML>\n";
print "</PRE>";
print "</HTML>\n";
?>
]]>
</programlisting>
</example>
</refsect1>
@ -1025,7 +1057,8 @@ Upload file: &lt;input type="file" name="lob_upload">&lt;br>
<example>
<title>OCIFetchStatement</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
/* OCIFetchStatement example mbritton@verinet.com (990624) */
$conn = OCILogon("scott","tiger");
@ -1036,31 +1069,32 @@ OCIExecute($stmt);
$nrows = OCIFetchStatement($stmt,$results);
if ( $nrows > 0 ) {
print "&lt;TABLE BORDER=\"1\">\n";
print "&lt;TR>\n";
print "<TABLE BORDER=\"1\">\n";
print "<TR>\n";
while ( list( $key, $val ) = each( $results ) ) {
print "&lt;TH>$key&lt;/TH>\n";
print "<TH>$key</TH>\n";
}
print "&lt;/TR>\n";
print "</TR>\n";
for ( $i = 0; $i &lt; $nrows; $i++ ) {
for ( $i = 0; $i < $nrows; $i++ ) {
reset($results);
print "&lt;TR>\n";
print "<TR>\n";
while ( $column = each($results) ) {
$data = $column['value'];
print "&lt;TD>$data[$i]&lt;/TD>\n";
print "<TD>$data[$i]</TD>\n";
}
print "&lt;/TR>\n";
print "</TR>\n";
}
print "&lt;/TABLE>\n";
print "</TABLE>\n";
} else {
echo "No data found&lt;BR>\n";
echo "No data found<BR>\n";
}
print "$nrows Records Selected&lt;BR>\n";
print "$nrows Records Selected<BR>\n";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
]]>
</programlisting>
</example>
</refsect1>
@ -1112,33 +1146,35 @@ OCILogoff($conn);
<example>
<title>OCIColumnName</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;PRE>\n";
<![CDATA[
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("scott", "tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
print "&lt;TABLE BORDER=\"1\">";
print "&lt;TR>";
print "&lt;TH>Name&lt;/TH>";
print "&lt;TH>Type&lt;/TH>";
print "&lt;TH>Length&lt;/TH>";
print "&lt;/TR>";
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>Name</TH>";
print "<TH>Type</TH>";
print "<TH>Length</TH>";
print "</TR>";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i &lt;= $ncols; $i++ ) {
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_type = OCIColumnType($stmt,$i);
$column_size = OCIColumnSize($stmt,$i);
print "&lt;TR>";
print "&lt;TD>$column_name&lt;/TD>";
print "&lt;TD>$column_type&lt;/TD>";
print "&lt;TD>$column_size&lt;/TD>";
print "&lt;/TR>";
print "<TR>";
print "<TD>$column_name</TD>";
print "<TD>$column_type</TD>";
print "<TD>$column_size</TD>";
print "</TR>";
}
OCIFreeStatement($stmt);
OCILogoff($conn);
print "&lt;/PRE>";
print "&lt;/HTML>\n";
print "</PRE>";
print "</HTML>\n";
?>
]]>
</programlisting>
</example>
</para>
@ -1174,34 +1210,36 @@ OCILogoff($conn);
<example>
<title>OCIColumnSize</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;PRE>\n";
<![CDATA[
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("scott", "tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
print "&lt;TABLE BORDER=\"1\">";
print "&lt;TR>";
print "&lt;TH>Name&lt;/TH>";
print "&lt;TH>Type&lt;/TH>";
print "&lt;TH>Length&lt;/TH>";
print "&lt;/TR>";
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>Name</TH>";
print "<TH>Type</TH>";
print "<TH>Length</TH>";
print "</TR>";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i &lt;= $ncols; $i++ ) {
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_type = OCIColumnType($stmt,$i);
$column_size = OCIColumnSize($stmt,$i);
print "&lt;TR>";
print "&lt;TD>$column_name&lt;/TD>";
print "&lt;TD>$column_type&lt;/TD>";
print "&lt;TD>$column_size&lt;/TD>";
print "&lt;/TR>";
print "<TR>";
print "<TD>$column_name</TD>";
print "<TD>$column_type</TD>";
print "<TD>$column_size</TD>";
print "</TR>";
}
print "&lt;/TABLE>";
print "</TABLE>";
OCIFreeStatement($stmt);
OCILogoff($conn);
print "&lt;/PRE>";
print "&lt;/HTML>\n";
print "</PRE>";
print "</HTML>\n";
?>
]]>
</programlisting>
</example>
</para>
@ -1236,33 +1274,35 @@ OCILogoff($conn);
<example>
<title>OCIColumnType</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;PRE>\n";
<![CDATA[
<?php
print "<HTML><PRE>\n";
$conn = OCILogon("scott", "tiger");
$stmt = OCIParse($conn,"select * from emp");
OCIExecute($stmt);
print "&lt;TABLE BORDER=\"1\">";
print "&lt;TR>";
print "&lt;TH>Name&lt;/TH>";
print "&lt;TH>Type&lt;/TH>";
print "&lt;TH>Length&lt;/TH>";
print "&lt;/TR>";
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>Name</TH>";
print "<TH>Type</TH>";
print "<TH>Length</TH>";
print "</TR>";
$ncols = OCINumCols($stmt);
for ( $i = 1; $i &lt;= $ncols; $i++ ) {
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
$column_type = OCIColumnType($stmt,$i);
$column_size = OCIColumnSize($stmt,$i);
print "&lt;TR>";
print "&lt;TD>$column_name&lt;/TD>";
print "&lt;TD>$column_type&lt;/TD>";
print "&lt;TD>$column_size&lt;/TD>";
print "&lt;/TR>";
print "<TR>";
print "<TD>$column_name</TD>";
print "<TD>$column_type</TD>";
print "<TD>$column_size</TD>";
print "</TR>";
}
OCIFreeStatement($stmt);
OCILogoff($conn);
print "&lt;/PRE>";
print "&lt;/HTML>\n";
print "</PRE>";
print "</HTML>\n";
?>
]]>
</programlisting>
</example>
</para>
@ -1292,11 +1332,13 @@ OCILogoff($conn);
<example>
<title>OCIServerVersion</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
$conn = OCILogon("scott","tiger");
print "Server Version: " . OCIServerVersion($conn);
OCILogOff($conn);
?>
]]>
</programlisting>
</example>
</para>
@ -1335,19 +1377,21 @@ OCILogoff($conn);
<example>
<title>Code examples</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;PRE>";
<![CDATA[
<?php
print "<HTML><PRE>";
$conn = OCILogon("scott","tiger");
$sql = "delete from emp where deptno = 10";
$stmt = OCIParse($conn,$sql);
if ( OCIStatementType($stmt) == "DELETE" ) {
die "You are not allowed to delete from this table&lt;BR>";
die "You are not allowed to delete from this table<BR>";
}
OCILogoff($conn);
print "&lt;/PRE>&lt;/HTML>";
print "</PRE></HTML>";
?>
]]>
</programlisting>
</example>
</para>
@ -1377,18 +1421,19 @@ OCILogoff($conn);
<example>
<title>Using a REF CURSOR from a stored procedure</title>
<programlisting>
&lt;?php
<![CDATA[
<?php
// suppose your stored procedure info.output returns a ref cursor in :data
$conn = OCILogon("scott","tiger");
$curs = OCINewCursor($conn);
$stmt = OCIParse($conn,"begin info.output(:data); end;");
ocibindbyname($stmt,"data",&amp;$curs,-1,OCI_B_CURSOR);
ocibindbyname($stmt,"data",&$curs,-1,OCI_B_CURSOR);
ociexecute($stmt);
ociexecute($curs);
while (OCIFetchInto($curs,&amp;$data)) {
while (OCIFetchInto($curs,&$data)) {
var_dump($data);
}
@ -1396,6 +1441,7 @@ OCIFreeStatement($stmt);
OCIFreeCursor($curs);
OCILogoff($conn);
?>
]]>
</programlisting>
</example>
</para>
@ -1403,39 +1449,41 @@ OCILogoff($conn);
<example>
<title>Using a REF CURSOR in a select statement</title>
<programlisting>
&lt;?php
print "&lt;HTML>&lt;BODY>";
<![CDATA[
<?php
print "<HTML><BODY>";
$conn = OCILogon("scott","tiger");
$count_cursor = "CURSOR(select count(empno) num_emps from emp " .
"where emp.deptno = dept.deptno) as EMPCNT from dept";
$stmt = OCIParse($conn,"select deptno,dname,$count_cursor");
ociexecute($stmt);
print "&lt;TABLE BORDER=\"1\">";
print "&lt;TR>";
print "&lt;TH>DEPT NAME&lt;/TH>";
print "&lt;TH>DEPT #&lt;/TH>";
print "&lt;TH># EMPLOYEES&lt;/TH>";
print "&lt;/TR>";
print "<TABLE BORDER=\"1\">";
print "<TR>";
print "<TH>DEPT NAME</TH>";
print "<TH>DEPT #</TH>";
print "<TH># EMPLOYEES</TH>";
print "</TR>";
while (OCIFetchInto($stmt,&amp;$data,OCI_ASSOC)) {
print "&lt;TR>";
print "<TR>";
$dname = $data["DNAME"];
$deptno = $data["DEPTNO"];
print "&lt;TD>$dname&lt;/TD>";
print "&lt;TD>$deptno&lt;/TD>";
print "<TD>$dname</TD>";
print "<TD>$deptno</TD>";
ociexecute($data[ "EMPCNT" ]);
while (OCIFetchInto($data[ "EMPCNT" ],&amp;$subdata,OCI_ASSOC)) {
$num_emps = $subdata["NUM_EMPS"];
print "&lt;TD>$num_emps&lt;/TD>";
print "<TD>$num_emps</TD>";
}
print "&lt;/TR>";
print "</TR>";
}
print "&lt;/TABLE>";
print "&lt;/BODY>&lt;/HTML>";
print "</TABLE>";
print "</BODY></HTML>";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
]]>
</programlisting>
</example>
</para>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<!-- $Revision: 1.16 $ -->
<reference id="ref.openssl">
<title>OpenSSL functions</title>
<titleabbrev>OpenSSL</titleabbrev>
@ -206,9 +206,11 @@
<example>
<title><function>openssl_error_string</function> example</title>
<programlisting role="php">
<![CDATA[
// lets assume you just called an openssl function that failed
while($msg = openssl_error_string)
echo $msg . "&lt;br&gt;";
]]>
</programlisting>
</example>
</para>
@ -330,6 +332,7 @@ while($msg = openssl_error_string)
<example>
<title><function>openssl_open</function> example</title>
<programlisting role="php">
<![CDATA[
// $sealed and $env_key are assumed to contain the sealed data
// and our envelope key, both given to us by the sealer.
@ -347,6 +350,7 @@ else
// free the private key from memory
openssl_free_key($pkeyid);
]]>
</programlisting>
</example>
</para>
@ -395,6 +399,7 @@ openssl_free_key($pkeyid);
<example>
<title><function>openssl_seal</function> example</title>
<programlisting role="php">
<![CDATA[
// $data is assumed to contain the data to be sealed
// fetch public keys for our recipients, and ready them
@ -415,6 +420,7 @@ openssl_seal($data, $sealed, $ekeys, array($pk1,$pk2));
// free the keys from memory
openssl_free_key($pk1);
openssl_free_key($pk2);
]]>
</programlisting>
</example>
</para>
@ -456,6 +462,7 @@ openssl_free_key($pk2);
<example>
<title><function>openssl_sign</function> example</title>
<programlisting role="php">
<![CDATA[
// $data is assumed to contain the data to be signed
// fetch private key from file and ready it
@ -469,6 +476,7 @@ openssl_sign($data, $signature, $pkeyid);
// free the key from memory
openssl_free_key($pkeyid);
]]>
</programlisting>
</example>
</para>
@ -510,6 +518,7 @@ openssl_free_key($pkeyid);
<example>
<title><function>openssl_verify</function> example</title>
<programlisting role="php">
<![CDATA[
// $data and $signature are assumed to contain the data and the signature
// fetch public key from certificate and ready it
@ -529,6 +538,7 @@ else
// free the key from memory
openssl_free_key($pubkeyid);
]]>
</programlisting>
</example>
</para>
@ -568,6 +578,7 @@ openssl_free_key($pubkeyid);
<example>
<title><function>openssl_pkcs7_decrypt</function> example</title>
<programlisting role="php">
<![CDATA[
// $cert and $key are assumed to contain your personal certificate and private
// key pair, and that you are the recipient of an S/MIME message
$infilename = "encrypted.msg"; // this file holds your encrypted message
@ -577,7 +588,7 @@ if (openssl_pkcs7_decrypt($infilename, $outfilename, $cert, $key))
echo "decrypted!";
else
echo "failed to decrypt!";
]]>
</programlisting>
</example>
</para>
@ -625,10 +636,11 @@ else
<example>
<title><function>openssl_pkcs7_encrypt</function> example</title>
<programlisting role="php">
<![CDATA[
// the message you want to encrypt and send to your secret agent
// in the field, known as nighthawk. You have his certificate
// in the file nighthawk.pem
$data = &lt;&lt;&lt;EOD
$data = <<<EOD
Nighthawk,
Top secret, for your eyes only!
@ -644,13 +656,14 @@ fwrite($fp, $data);
fclose($fp);
// encrypt it
if (openssl_pkcs7_encrypt("msg.txt", "enc.txt", "nighthawk.pem",
array("To" =&gt; "nighthawk@agent.com", // keyed syntax
"From: HQ &lt;hq@cia.com&gt;", // indexed syntax
"Subject" =&gt; "Eyes only")))
array("To" => "nighthawk@agent.com", // keyed syntax
"From: HQ <hq@cia.com>", // indexed syntax
"Subject" => "Eyes only")))
{
// message encrypted - send it!
exec(ini_get("sendmail_path") . " &lt; enc.txt");
exec(ini_get("sendmail_path") . " < enc.txt");
}
]]>
</programlisting>
</example>
</para>
@ -710,9 +723,10 @@ if (openssl_pkcs7_encrypt("msg.txt", "enc.txt", "nighthawk.pem",
<example>
<title><function>openssl_pkcs7_sign</function> example</title>
<programlisting role="php">
<![CDATA[
// the message you want to sign so that recipient can be sure it was you that
// sent it
$data = &lt;&lt;&lt;EOD
$data = <<<EOD
You have my authorization to spend $10,000 on dinner expenses.
@ -725,13 +739,14 @@ fclose($fp);
// encrypt it
if (openssl_pkcs7_sign("msg.txt", "signed.txt", "mycert.pem",
array("mycert.pem", "mypassphrase"),
array("To" =&gt; "joes@sales.com", // keyed syntax
"From: HQ &lt;ceo@sales.com&gt;", // indexed syntax
"Subject" =&gt; "Eyes only"))
array("To" => "joes@sales.com", // keyed syntax
"From: HQ <ceo@sales.com>", // indexed syntax
"Subject" => "Eyes only"))
{
// message signed - send it!
exec(ini_get("sendmail_path") . " &lt; signed.txt");
}
]]>
</programlisting>
</example>
</para>