<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
    <channel>
        <title>Tutorials :: Using CUBRID with apache and PHP in Linux</title>
        <link>http://www.cubrid.org/?mid=using_cubrid_with_apache_php_in_linux</link>
        <description>Tutorials :: Using CUBRID with apache and PHP in Linux</description>
        <language>en</language>
        <pubDate>Tue, 06 Apr 2010 16:09:19 -0800</pubDate>
        <lastBuildDate>Wed, 28 Sep 2011 05:45:51 -0800</lastBuildDate>
        <generator>XpressEngine 1.4.4.1</generator>
                        										        <item>
            <title>Tutorials :: Using CUBRID with apache and PHP in Linux</title>
            <dc:creator>admin</dc:creator>
            <link>http://www.cubrid.org/using_cubrid_with_apache_php_in_linux</link>
            <guid isPermaLink="true">http://www.cubrid.org/using_cubrid_with_apache_php_in_linux</guid>
                                    <description><![CDATA[<h1>Using CUBRID with Apache, PHP in LINUX - Installation with phpize</h1>
<p><strong>Introduction: </strong>This chapter introduces how to install PHP CUBRID module with phpize to use CUBRID after installing  Apache Web server and PHP in LINUX, and provides simply how to interwork with CUBRID. For more information about interworking, see  section " PHP API " of the manual.</p>
<p><strong>Applicable to: </strong>LINUX, CUBRID2008, Apache2.2.10, PHP5.2</p>

<div class="contents-table">
<h3>Table of Contents</h3>
<ul>
    <li><a href="#_Toc_T301">Installing Apache</a></li>
    <li><a href="#_Toc_T302">Installing PHP</a></li>
    <li><a href="#_Toc_T307">Installing CUBRID Module</a>
    <ul style="list-style-type: none;">
        <li><a href="#_Toc_T303">Running CUBRID</a></li>
        <li><a href="#_Toc_T304">Simple examples</a></li>
        <li><a href="#_Toc_T305">select.php</a></li>
        <li><a href="#_Toc_T306">insert.php</a></li>
    </ul>
    </li>
</ul>
</div>

<h3><a name="_Toc_T301"></a>Installing Apache</h3>
<p>This chapter introduces how to install Apache Web server in LINUX.  You can download the Apache Web server from <a target="_blank" href="http://httpd.apache.org/download.cgi">Apache download</a>.  Usually, download Unix Source below " Apache HTTP Server 2.2.1 0 is the best available version ", and then uncompress  the downloaded file (ex. <a target="_blank" href="http://archive.apache.org/dist/httpd/httpd-2.2.10.tar.gz">httpd-2.2.1 0.tar.gz</a>)  and install the server.</p>
<p>In this example, the server is installed under user account in general account. If you install it under root account, you can use  the default installation location (--prefix is not necessary and the installation location is usually /usr/local/apache2).</p>

<div class="code">
<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border-width: 1px 1px 1px 5px; border-style: dotted dotted dotted solid; border-color: rgb(102, 102, 102) rgb(102, 102, 102) rgb(102, 102, 102) rgb(34, 170, 238); padding: 5px;">
<p># Move the downloaded file to a user's home directory for installation. You can move it to any directory you want.  	A user's home directory is assumed to be /home/web.</p>
<p># The downloaded file name is assumed to be httpd-2.2.10.tar.gz.</p>
<p># Uncompress the file and extract tar.</p>
<p>tar xvfz httpd-2.2.10.tar.gz</p>
<p>or gzip -d httpd-2.2.10.tar.gz; tar xvf httpd-2.2.10.tar</p>
<p># After extracting tar, the httpd-2.2.10 directory is created and you can see installation files in it.</p>
<p>cd httpd-2.2.10</p>
<p># You need to complie for installation. Make sure to configure the modules to make them support dynamic loading before compiling.</p>
<p>./configure --enable-mods-shared=most --enable-modules=so --with-mpm=worker --enable-so --prefix=/home/web/apache2</p>
<p># If there is no error, start compiling.</p>
<p>make</p>
<p># If the compiling is successful, start installation.</p>
<p>make install</p>
<p># After installation, register the mail account of an administrator and the server name to the configuration file.</p>
<p>vi /home/web/apache2/conf/httpd.conf</p>
<p># Set ServerAdmin web_admin@cubrid.com (the e-mail address of a Web server administrator).</p>
<p># Register as ServerName my_hostname(server name or IP address).</p>
<p># Listen 8000 (If a installed user account is not root, the default port of the installed Apache Web server cannot be 80.  	It must be changed. Usually, 8000 is used.)</p>
<p># If you want to use 80, you need to change configuration to make the Web server work as the root account. Of course,  	you can run it as your current account. With the below configuration, the server works as root account although it is started  	in a general account.</p>
<p>cd /home/web/apache2/bin</p>
<p>chown root httpd</p>
<p>chmod +s httpd</p>
</div>
</div>

<div class="code">
<div editor_component="code_highlighter" code_type="Xml" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border-width: 1px 1px 1px 5px; border-style: dotted dotted dotted solid; border-color: rgb(102, 102, 102) rgb(102, 102, 102) rgb(102, 102, 102) rgb(34, 170, 238); padding: 5px;">
<p>cd /home/web/apache2/bin</p>
<p>apachectl start</p>
</div>
</div>

<p>After running the Web browser, enter http://localhost:8000 (for LINUX) or http://192.168.2.1:8000 (for PC. LINUX server IP is  	assumed to be 192.168.2.1) in the address bar . If 'It works!' is displayed, it means the server is successfully installed.</p>
<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image1.jpg" style="width: 223px; height: 54px;" alt=""/></p>

<p class="linkToTop"><a href="#Top">^ Top of page</a></p>
<h3><a name="_Toc_T302"></a>Installing PHP</h3>
<p>Stop the Apache Web server to install PHP.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border-width: 1px 1px 1px 5px; border-style: dotted dotted dotted solid; border-color: rgb(102, 102, 102) rgb(102, 102, 102) rgb(102, 102, 102) rgb(34, 170, 238); padding: 5px;">
<p>cd /home/web/apache2/bin</p>
<p>apachectl stop</p>
</div>
</div>

<p>You can download PHP from <a target="_blank" href="http://www.php.net/downloads.php">PHP download</a>. Usually, you can see the most recent version. Download PHP under <strong>Complete Source Code </strong>(ex. <a target="_blank" href="http://www.php.net/get/php-5.3.8.tar.gz/from/a/mirror">php-5.3.8.tar.gz</a>).</p>

<div class="code">
<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border-width: 1px 1px 1px 5px; border-style: dotted dotted dotted solid; border-color: rgb(102, 102, 102) rgb(102, 102, 102) rgb(102, 102, 102) rgb(34, 170, 238); padding: 5px;">
<p># It is assumed the downloaded file for installation is located in a user's home directory.</p>
<p># The downloaded file name is assumed to be php-5.3.8.tar.gz.</p>
<p># Uncompress PHP installtion module and extract tar.</p>
<p>tar xvfz php-5.3.8.tar.gz</p>
<p># Execute configure. (For PHP4.3, 4.4, use --enable-experimental-zts instead of --enable-zmaintainer-zts.)</p>
<p>./configure --prefix=/home/web/php --enable-zmaintainer-zts --with-apxs2=/home/web/apache2/bin/apxs</p>
<p># If there is no error, start compiling.</p>
<p>make</p>
<p># If the compiling is successful, start installation.</p>
<p>make install</p>
<p># After installation, copy php.ini-dist into /home/web/php/lib directory.</p>
<p>cp php.ini-dist /home/web/php/lib/php.ini</p>
<p># Register PHP extension to the Apache.</p>
<p>vi /home/web/apache2/conf/httpd.conf</p>
<p>AddType application/x-httpd-php .php .phtm</p>

</div>
</div>

<p>If it is installed successfully, run the Apache web server as follows:</p>

<div class="code">
<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border-width: 1px 1px 1px 5px; border-style: dotted dotted dotted solid; border-color: rgb(102, 102, 102) rgb(102, 102, 102) rgb(102, 102, 102) rgb(34, 170, 238); padding: 5px;">
<p>cd /home/web/apache2/bin</p>
<p>./apachectl start</p>
</div>
</div>

<p class="linkToTop"><a href="#Top">^ Top of page</a></p>
<h3><a name="_Toc_T307"></a>Checking whether PHP and CUBRID PHP module work</h3>
<p>Create phpinfo.php in documents root of Apache Web server (e.g. /home/web/apache2/htdocs) with the following.</p>
<p>&lt;? phpinfo.php ?&gt;</p>
<p>After running the Web browser, enter http://localhost:8000/phpinfo.php (for LINUX) or http://192.168.2.1:8000/phpinfo.php  (for PC. LINUX server IP is assumed to be 192.168.2.1) in the address bar. If you can see PHP as below, it is successfully installed.</p>
<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image2.jpg" style="width: 489px; height: 124px;" alt=""/></p>



<p class="linkToTop"><a href="#Top">^ Top of page</a></p>
<h3><a name="_Toc_T303"></a>Running CUBRID</h3>
<p>Make sure CUBRID service is running to interwork with CUBRID. For LINUX, log in as CUBRID admin account and start the service.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="Bash" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border-width: 1px 1px 1px 5px; border-style: dotted dotted dotted solid; border-color: rgb(102, 102, 102) rgb(102, 102, 102) rgb(102, 102, 102) rgb(34, 170, 238); padding: 5px;">
<p>cubrid service start</p>
</div>
</div>

<p>Now, use the CUBRID Manager Client to run database as follows: Note that JAVA Runtime Environment is needed to run the  CUBRID Manager Client that is developed in JAVA. You can download JAVA Runtime Environment from  <a target="_blank" href="http://java.sun.com/javase/downloads/index.jsp">JAVA download </a>. <strong> Java SE Runtime Environment (JRE)</strong>.</p>
<p>Run $CUBRID/cubridmanager/cmclient because CUBRID Manager Client can run in LINUX GUI environment.</p>
<p>If you want to install it on your PC, download the CUBRID Manager Client for Windows from the CUBRID homepage.  And if you want to install only the CUBRID Manager Client, just select " CLIENT_ONLY " in the installation option.</p>
<p>To run the CUBRID Manager Client on your PC, right-click the CUBRID icon in the Windows system tray,  then select [Tools] &gt; [CUBRID Manager] in the context menu. If only CUBRID Client is installed, go to [Start] &gt; [CUBRID] and  select [CUBRID Manager Client] to run.</p>
<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image3.jpg" style="width: 260px; height: 92px;" alt=""/>  <img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image4.jpg" style="width: 138px; height: 47px;" alt=""/></p>
<p>Select localhost and login. If this is first installation, just click [ Connect ] .</p>
<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image5.png" style="width: 462px; height: 394px;" alt=""/></p>
<p>If you connect your PC to a LINUX server, click [Add Host] to register a new host. Enter a name into the [Host name ] box (e.g. web server),  the IP address of LINUX into the [Address ] box, a user name into the [ User name ] box, user password into the [ Password ], and then  click [ Connect ]. This saves the information you entered and connects to LINUX server. You can just select the name you  registered (e.g. web server) in [Host name ] box from the next time.</p>
<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image6.png" style="width: 401px; height: 350px;" alt=""/></p>
<p>When you double-click a database at the left side of the screen, you can see the login dialog for the database. You can just click [ OK ],  because there is no database user password at the first installation.</p>
<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image7.png" style="width: 390px; height: 305px;" alt=""/></p>
<p>After login to the database, right-click the database and then select [ Start database server ] in context menu to start the database.</p>
<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image8.png" style="width: 229px; height: 169px;" alt=""/></p>

<p class="linkToTop"><a href="#Top">^ Top of page</a></p>
<h3><a name="_Toc_T304"></a>Simple examples</h3>
<p>This is a simple example that shows actual interworking between PHP and CUBRID. There are only the most basic functions and some special  cautions.</p>
<p>To perform this example, the database and CUBRID BROKER you want to connect must be running. Here, we just use "demodb" database that is  automatically created during installation.</p>
<p>Create the following source in the DOCUMENT_ROOT (e.g. /home/web/apache2/htdocs).</p>
<p>The IP address of LINUX server in an example is assumed to be 192.168.2.1. You can enter your actual IP address.  Test just like http://192.168.2.1/select.php in a Web browser.</p>

<p class="linkToTop"><a href="#Top">^ Top of page</a></p>
<h3><a name="_Toc_T305"></a>select.php</h3>

<div class="code">
<div editor_component="code_highlighter" code_type="Php" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border-width: 1px 1px 1px 5px; border-style: dotted dotted dotted solid; border-color: rgb(102, 102, 102) rgb(102, 102, 102) rgb(102, 102, 102) rgb(34, 170, 238); padding: 5px;">
<p>&lt;html&gt;&lt;head&gt;&lt;meta http-equiv='content-type' content='text/html; charset=euc-kr'&gt;&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;center&gt;</p>
<p>&lt;table border=2&gt;</p>
<p>&lt;?</p>

<p>// Set server information for CUBRID connection. The IP address is the one where the CUBRID (CUBRID BROKER) server is  	installed (localhost in this example), and the port is the port number through which you want to connect to the CUBRID (CUBRID BROKER) server.  	The port number is the default during installation. For more accurate information, see the CUBRID Administrator's Guide.</p>
<p>    $host_ip = "192.168.2.1";</p>
<p>    $host_port = 33000;</p>
<p>    $db_name = "demodb";</p>

<p>// Connect to CUBRID server.</p>
<p>    $cubrid_con = @cubrid_connect($host_ip, $host_port, $db_name);</p>
<p>    if (!$cubrid_con) {</p>
<p>        echo "Database Connection Error: " . cubrid_error_msg();</p>
<p>        exit;</p>
<p>    }</p>
<p>?&gt;</p>

<p>&lt;?</p>
<p>$sql = "select code, name, players from event";</p>
<p>// Request the CUBRID Server for the results of the SQL statement.</p>
<p>$result = cubrid_execute($cubrid_con, $sql);</p>
<p>if ($result) {</p>
<p>        // Get the column names from the result set created by the SQL query.</p>
<p>        $columns = cubrid_column_names($result);</p>
<p>// Get the number of columns in the result set created by the SQL query.</p>
<p>        $num_fields = cubrid_num_cols($result);</p>
<p>       // List the column names of the result set on the screen.</p>
<p>                echo("&lt;tr&gt;");</p>
<p>        while (list($key, $colname) = each($columns)) {</p>
<p>                 	echo("&lt;td align=center&gt;$colname&lt;/td&gt;");</p>
<p>        }</p>
<p>                echo("&lt;/tr&gt;");</p>

<p>       // Get the results rows from the result set.</p>
<p>        while ($row = cubrid_fetch($result)) {</p>
<p>                echo("&lt;tr&gt;");</p>
<p>                 	for ($i = 0; $i &lt; $num_fields; $i++) {</p>
<p>                    	     echo("&lt;td align=center&gt;");</p>
<p>                    	     echo($row[$i]);</p>
<p>                    	     echo("&lt;/td&gt;");</p>
<p>                }</p>
<p>                echo("&lt;/tr&gt;");</p>
<p>        }</p>
<p>}</p>

<p>/ / CUBRID runs in 3-tier architecture. Even when calling select for transaction processing, it is processed as a part of the  	transaction. Therefore, the transaction needs to be committed or rolled back even though SELECT was called for smooth performance.  	For more information, see CUBRID Administrator's Guide.</p>
<p>        cubrid_commit($cubrid_con);</p>
<p>cubrid_disconnect($cubrid_con);</p>
<p>?&gt;</p>

<p>  &lt;/body&gt;&lt;/html&gt;</p>
</div>
</div>

<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image9.jpg" style="width: 275px; height: 120px;" alt=""/></p>

<p class="linkToTop"><a href="#Top">^ Top of page</a></p>
<h3><a name="_Toc_T306"></a>insert.php</h3>

<div class="code">
<div editor_component="code_highlighter" code_type="Php" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false" style="border-width: 1px 1px 1px 5px; border-style: dotted dotted dotted solid; border-color: rgb(102, 102, 102) rgb(102, 102, 102) rgb(102, 102, 102) rgb(34, 170, 238); padding: 5px;">
<p>&lt;html&gt;&lt;head&gt;&lt;meta http-equiv='content-type' content='text/html; charset=euc-kr'&gt;&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;center&gt;</p>
<p>&lt;table border=2&gt;</p>
<p>&lt;?</p>
<p>// Set server information for CUBRID connection. The IP address is the one where the CUBRID (CUBRID CAS) server is  	installed (localhost in this example), and the port is the port number through which you want to connect to the CUBRID (CUBRID BROKER) server.  	The port number is the default during installation. For more accurate information, see the CUBRID Administrator's Guide.</p>
<p>    $host_ip = "192.168.2.1";</p>
<p>    $host_port = 33000;</p>
<p>    $db_name = "demodb";</p>

<p>// Connect to CUBRID Server.</p>
<p>    $cubrid_con = @cubrid_connect($host_ip, $host_port, $db_name);</p>
<p>    if (!$cubrid_con) {</p>
<p>        echo "Database Connection Error";</p>
<p>        exit;</p>
<p>}</p>
<p>?&gt;</p>

<p>&lt;?</p>
<p>$sql = "insert into event(code, sports, name, gender, players) values(10000, 'TaeKwonDo','Unlimited Weight', 'M', 2)";</p>
<p>// Request the CUBRID Server for the query of the SQL statement.</p>
<p>$result = @cubrid_execute($cubrid_con, $sql);</p>
<p>if ($result == true) {</p>
<p>        // It is successful, so commit it.</p>
<p>        cubrid_commit($cubrid_con);</p>
<p>        echo(" Successfully inserted");</p>
<p>} else {</p>
<p>        // Error occurred, so error message is displayed and rollback is called.</p>
<p>        echo(cubrid_error_msg());</p>
<p>        cubrid_rollback($cubrid_con);</p>
<p>}</p>
<p>cubrid_disconnect($cubrid_con);</p>
<p>?&gt;</p>
<p>&lt;/body&gt;&lt;/html&gt;</p>
</div>
</div>

<p><img editor_component="image_link" src="http://www.cubrid.org/files/attach/images/tutorials/3/image10.jpg" style="width: 232px; height: 78px;" alt=""/></p><p></p>]]></description>
                        <pubDate>Tue, 06 Apr 2010 15:10:09 -0800</pubDate>
                                </item>
            </channel>
</rss>
