php-doc-en/reference/pdo_cubrid/reference.xml
2014-09-05 07:44:07 +00:00

321 lines
9.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<reference xml:id="ref.pdo-cubrid" xmlns="http://docbook.org/ns/docbook">
<title>CUBRID Functions (PDO_CUBRID)</title>
<titleabbrev>CUBRID (PDO)</titleabbrev>
<partintro>
<section xml:id="pdo-cubrid.intro">
&reftitle.intro;
<para>
PDO_CUBRID is a driver that implements the <link linkend="intro.pdo">PHP Data Objects (PDO) interface</link> to
enable access from PHP to CUBRID databases.
</para>
<note>
<para>
Current version of PDO_CUBRID doesn't support persistent connection now.
</para>
</note>
</section>
<!-- Information found in configure.xml -->
&reference.pdo-cubrid.configure;
<section xml:id="ref.pdo-cubrid.features">
<title>Features</title>
<table>
<title>PDO_CUBRID Features</title>
<tgroup cols="2">
<thead>
<row>
<entry>Feature</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>Scrollable cursors</entry>
<entry>
PDO_CUBRID supports scrollable cursors. The default cursor type is
forward only, and you can use parameter driver_options in
<function>PDO::prepare</function> to change cursor type.
</entry>
</row>
<row>
<entry>Timeout</entry>
<entry>PDO_CUBRID supports sql statement execution timeout setting;
You can use <function>PDO::setAttribute</function> to set timeout value.</entry>
</row>
<row>
<entry>Autocommit_mode and Transaction</entry>
<entry>
PDO_CUBRID supports both autocommit_mode and transaction, and
autocommit_mode is enabled by default. You can use
<function>PDO::setAttribute</function> to change its state.
<para>
If you use <function>PDO::beginTransaction</function> to begin a
transaction, it will disable autocommit_mode automatically and
restore it after <function>PDO::commit</function> or
<function>PDO::rollBack</function>. Note that before disabling the
autocommit_mode, any pending work is automatically committed.
</para>
</entry>
</row>
<row>
<entry>Multiple SQL Statements</entry>
<entry>PDO_CUBRID supports Multiple SQL statements. Multiple SQL
statements are separated by semicolons (;)</entry>
</row>
<row>
<entry>Schema Information</entry>
<entry>PDO_CUBRID implements a function
<function>PDO::cubrid_schema</function> to get schema information.
</entry>
</row>
<row>
<entry>LOBs</entry>
<entry>PDO_CUBRID supports BLOB/CLOB data type. The LOB in PDO is
represented as a stream, so you can insert LOBs by binding a stream,
and get LOBs by reading a stream returned by CUBRID PDO. For example:
<para>
<example><title>Insert LOBs in CUBRID PDO</title>
<programlisting role="php">
<![CDATA[
<?php
$fp = fopen('lob_test.png', 'rb');
$sql_stmt = "INSERT INTO lob_test(name, content) VALUES('lob_test.png', ?)";
$stmt = $dbh->prepare($sql_stmt);
$ret = $stmt->bindParam(1, $fp, PDO::PARAM_LOB);
$ret = $stmt->execute();
?>
]]>
</programlisting>
</example>
</para>
<para>
<example><title>Fetch LOBs in CUBRID PDO</title>
<programlisting role="php">
<![CDATA[
<?php
$sql_stmt = "SELECT content FROM lob_test WHERE name='lob_test.png'";
$stmt = $dbh->prepare($sql_stmt);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_NUM);
header("Content-Type: image/png");
fpassthru($result[0]);
?>
]]>
</programlisting>
</example>
</para>
</entry>
</row>
<row>
<entry>Column meta</entry>
<entry>
The <function>PDOStatement::getColumnMeta</function> in CUBRID PDO
will return an associative array containing the following values:
<simplelist>
<member>type</member>
<member>name</member>
<member>table</member>
<member>def</member>
<member>precision</member>
<member>scale</member>
<member>not_null</member>
<member>auto_increment</member>
<member>unique_key</member>
<member>multiple_key</member>
<member>primary_key</member>
<member>foreign_key</member>
<member>reverse_index</member>
<member>reverse_unique</member>
</simplelist>
</entry>
</row>
<row>
<entry>Collection Data Type</entry>
<entry>PDO_CUBRID supports SET/MULTISET/SEQUENCE data type. If you don't specify data type,
the default data type is char,for example:
<para>
<example><title>Insert set in CUBRID PDO with default data type.</title>
<programlisting role="php">
<![CDATA[
<?php
$conn_str ="cubrid:dbname=demodb;host=localhost;port=33000";
$cubrid_pdo = new PDO($conn_str, 'dba', '');
$cubrid_pdo->exec("DROP TABLE if exists test_tbl");
$cubrid_pdo->exec("CREATE TABLE test_tbl (col_1 SET(VARCHAR))");
$sql_stmt_insert = "INSERT INTO test_tbl VALUES (?);";
$stmt = $cubrid_pdo->prepare($sql_stmt_insert);
$data = array("abc","def","ghi");
$ret = $stmt->bindParam(1, $data, PDO::PARAM_NULL);
$ret = $stmt->execute();
var_Dump($ret);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example><title>Specify data type when insert set in CUBRID PDO</title>
<programlisting role="php">
<![CDATA[
<?php
$conn_str ="cubrid:dbname=demodb;host=localhost;port=33000";
$cubrid_pdo = new PDO($conn_str, 'dba', '');
$cubrid_pdo->exec("DROP TABLE if exists test_tbl");
$cubrid_pdo->exec("CREATE TABLE test_tbl (col_1 SET(int))");
$sql_stmt_insert = "INSERT INTO test_tbl VALUES (?);";
$stmt = $cubrid_pdo->prepare($sql_stmt_insert);
$data = array(1,2,3,4);
$ret = $stmt->bindParam(1, $data, 0,0,"int");
$ret = $stmt->execute();
var_Dump($ret);
?>
]]>
</programlisting>
</example>
</para>
CUBRID Bind Data Types:(The fifth parameter of PDOStatement::bindParam):
<simplelist>
<member>CHAR</member>
<member>STRING</member>
<member>NCHAR</member>
<member>VARNCHAR</member>
<member>BIT</member>
<member>VARBIT</member>
<member>NUMERIC</member>
<member>NUMBER</member>
<member>INT</member>
<member>SHORT</member>
<member>BIGINT</member>
<member>MONETARY</member>
<member>FLOAT</member>
<member>DOUBLE</member>
<member>DATE</member>
<member>TIME</member>
<member>DATETIME</member>
<member>TIMESTAMP</member>
</simplelist>
</entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<!-- Information found in constants.xml -->
&reference.pdo-cubrid.constants;
</partintro>
<refentry xml:id="ref.pdo-cubrid.connection">
<refnamediv>
<refname>PDO_CUBRID DSN</refname>
<refpurpose>Connecting to CUBRID databases</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<para>
The PDO_CUBRID Data Source Name (DSN) is composed of the following elements, delimited by semicolons:
<variablelist>
<varlistentry>
<term>DSN prefix</term>
<listitem>
<para>
The DSN prefix is <userinput>cubrid:</userinput>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>host</literal></term>
<listitem>
<para>
The hostname on which the database server resides.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>port</literal></term>
<listitem>
<para>
The port on which the database server is running.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>dbname</literal></term>
<listitem>
<para>
The name of the database.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
When you estalish the connection to CUBRID, you should give username and
password except DSN.
</para>
</note>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>PDO_CUBRID DSN examples</title>
<para>
The following example shows a PDO_CUBRID DSN for connecting to a CUBRID database:
<programlisting><![CDATA[
cubrid:host=localhost;port=33000;dbname=demodb
]]>
</programlisting>
</para>
</example>
</para>
</refsect1>
</refentry>
&reference.pdo-cubrid.entities.PDO;
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->