📄 function.pg-field-size.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Returns the internal storage size of the named field</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-field-prtlen.html">pg_field_prtlen</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-field-table.html">pg_field_table</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.pg-field-size" class="refentry"> <div class="refnamediv"> <h1 class="refname">pg_field_size</h1> <p class="verinfo">(PHP 4 >= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_field_size</span> — <span class="dc-title"> Returns the internal storage size of the named field </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>pg_field_size</b></b></span> ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$result</tt></span> , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$field_number</tt></span> )</div> <p class="para rdfs-comment"> <b>pg_field_size()</b> returns the internal storage size (in bytes) of the field number in the given PostgreSQL <i><tt class="parameter">result</tt></i>. </p> <blockquote><p><b class="note">Note</b>: This function used to be called <b>pg_fieldsize()</b>. <br /> </p></blockquote> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">result</tt></i></span> <dd> <p class="para"> PostgreSQL query result resource, returned by <a href="function.pg-query.html" class="function">pg_query()</a>, <a href="function.pg-query-params.html" class="function">pg_query_params()</a> or <a href="function.pg-execute.html" class="function">pg_execute()</a> (among others). </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">field_number</tt></i></span> <dd> <p class="para"> Field number, starting from 0. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The internal field storage size (in bytes). -1 indicates a variable length field. <b><tt>FALSE</tt></b> is returned on error. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Getting information about fields</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /> $dbconn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">) or die(</span><span style="color: #DD0000">"Could not connect"</span><span style="color: #007700">);<br /><br /> </span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">, </span><span style="color: #DD0000">"select * from authors where author = 'Orwell'"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_num_fields</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br /> for (</span><span style="color: #0000BB">$j </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$j </span><span style="color: #007700">< </span><span style="color: #0000BB">$i</span><span style="color: #007700">; </span><span style="color: #0000BB">$j</span><span style="color: #007700">++) {<br /> echo </span><span style="color: #DD0000">"column $j\n"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$fieldname </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_field_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">, </span><span style="color: #0000BB">$j</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">"fieldname: $fieldname\n"</span><span style="color: #007700">;<br /> echo </span><span style="color: #DD0000">"printed length: " </span><span style="color: #007700">. </span><span style="color: #0000BB">pg_field_prtlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">, </span><span style="color: #0000BB">$fieldname</span><span style="color: #007700">) . </span><span style="color: #DD0000">" characters\n"</span><span style="color: #007700">;<br /> echo </span><span style="color: #DD0000">"storage length: " </span><span style="color: #007700">. </span><span style="color: #0000BB">pg_field_size</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">, </span><span style="color: #0000BB">$j</span><span style="color: #007700">) . </span><span style="color: #DD0000">" bytes\n"</span><span style="color: #007700">;<br /> echo </span><span style="color: #DD0000">"field type: " </span><span style="color: #007700">. </span><span style="color: #0000BB">pg_field_type</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">, </span><span style="color: #0000BB">$j</span><span style="color: #007700">) . </span><span style="color: #DD0000">" \n\n"</span><span style="color: #007700">;<br /> }<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>column 0fieldname: authorprinted length: 6 charactersstorage length: -1 bytesfield type: varchar column 1fieldname: yearprinted length: 4 charactersstorage length: 2 bytesfield type: int2 column 2fieldname: titleprinted length: 24 charactersstorage length: -1 bytesfield type: varchar </pre></div> </pre></div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.pg-field-prtlen.html" class="function" rel="rdfs-seeAlso">pg_field_prtlen()</a></li> <li class="member"><a href="function.pg-field-type.html" class="function" rel="rdfs-seeAlso">pg_field_type()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-field-prtlen.html">pg_field_prtlen</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-field-table.html">pg_field_table</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -