连锁当家运维手册


linux 中php连接hana

<p>环境centos7 php7 apache</p> <p>一、首先安装hana HDB客户端 上传HDB_CLIENT_LINUXINTEL.zip到服务器root目录下</p> <p>解压文件 unzip -x HDB_CLIENT_LINUXINTEL.zip</p> <p>更改HDB客户端权限 chmod -R 777 /root/HDB_CLIENT_LINUXINTEL/*</p> <p>进入HDB客户端目录 cd HDB_CLIENT_LINUXINTEL</p> <p>安装HDB客户端 ./hdbinst</p> <p>二、安装odbc 下载odbc文件unixODBC-2.3.4.tar.gz</p> <p>解压odbc文件 tar zxvf unixODBC-2.3.4.tar.gz</p> <p>cd unixODBC-2.3.4</p> <pre><code>./configure --prefix=/usr/local/unixODBC -enable-iconv=yes --with-iconv-char-enc=UTF-8</code></pre> <p>make make install</p> <p>vim /usr/local/unixODBC/etc/odbc.ini 编辑内容如下 [HDB] driver = /usr/sap/hdbclient/libodbcHDB.so ServerNode = demo.upyuan.com:30015 CHAR_AS_UTF8=true</p> <p>====================</p> <p><a href="http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.gz">http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.gz</a></p> <p>yum install zlib-devel pcre-devel pcre</p> <p>yum remove apr apr-util </p> <p>yum install gcc-c++</p> <p>yum -y install libtool autoconf automake</p> <p><a href="https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz">https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz</a> tar -zxvf cmake-3.10.1.tar.gz</p> <p>./configure make &amp;&amp; make install</p> <p><a href="http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz">http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz</a> tar -zxvf apr-1.6.3.tar.gz cd apr-1.5.2</p> <p>vim configure 注释这两行</p> <pre><code>#RM=$ac_cv_prog_RM #ac_cv_prog_RM=&amp;quot;rm&amp;quot;</code></pre> <p>./configure --prefix=/usr/local/apr/ make &amp;&amp; make install</p> <p>yum install expat-devel</p> <p><a href="http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz">http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz</a> tar -zxvf apr-util-1.6.1.tar.gz cd apr-util-1.6.1 ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/ make &amp;&amp; make install</p> <p>cd /root/httpd-2.4.29</p> <p>./configure \ --prefix=/usr/local/apache \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util \ --enable-so \ --enable-deflate=shared \ --enable-expires=shared \ --enable-rewrite=shared \ --enable-static-support</p> <p>make &amp;&amp; make install</p> <p>修改apache conf ServerName localhost:80</p> <h3>安装 php</h3> <p><a href="http://cn.php.net/distributions/php-7.0.27.tar.gz">http://cn.php.net/distributions/php-7.0.27.tar.gz</a></p> <p>====</p> <p>yum -y install make gcc-c++ cmake bison-devel ncurses-devel php70-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel postgresql-libs postgresql-devel </p> <pre><code>./configure \ --prefix=/usr/local/php \ --with-apxs2=/usr/local/apache/bin/apxs \ --with-zlib \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-zlib-dir \ --enable-mbstring \ --with-custom-odbc=/usr/local/unixODBC/ \ --with-pgsql=/usr/pgsql-10 \ --with-pdo-pgsql=/usr/pgsql-10 </code></pre> <p>cd /root/php-7.0.27/ext/odbc</p> <p>vim odbc.h</p> <pre><code>#include &amp;lt;sql.h&amp;gt; #include &amp;lt;sqlext.h&amp;gt; #include &amp;lt;odbcinst.h&amp;gt;</code></pre> <p>make make install</p> <p>重启apahce</p> <p>下面是php连接示例</p> <pre><code>&amp;lt;?php header(&amp;quot;Content-type: text/html; charset=utf-8&amp;quot;); $host = &amp;quot;demo.upyuan.com:30015&amp;quot;; $db_name = &amp;quot;EB3&amp;quot;; $username = 'EB3'; $password = ''; $conn = odbc_connect(&amp;quot;HDB&amp;quot;,$db_name,$password,SQL_CUR_USE_ODBC); if (!$conn){ //echo odbc_errormsg ($conn); echo &amp;quot;this is error\n&amp;quot;; } //$sql = &amp;quot;&amp;quot;; //$sql=&amp;quot;insert into //colortbl(colorid,colorname,custid)values('8920','好','postgres')&amp;quot;; //$sql = iconv(&amp;quot;UTF-8&amp;quot;,&amp;quot;gb2312//IGNORE&amp;quot;,$sql); echo $sql; $sql = &amp;quot;select * from colortbl&amp;quot;; $rs = odbc_exec($conn,$sql); if (!$rs){ exit(&amp;quot;Error in SQL&amp;quot;); } //var_dump($rs); while(odbc_fetch_row($rs)){ for($i=1;$i&amp;lt;=odbc_num_fields($rs);$i++){ echo &amp;quot; &amp;quot;.odbc_result($rs,$i) .&amp;quot; &amp;quot;; } } exit();</code></pre> <pre><code>&amp;lt;?php header(&amp;quot;Content-type: text/html; charset=utf-8&amp;quot;); $host = &amp;quot;demo.upyuan.com:30015&amp;quot;; $db_name = &amp;quot;EB3&amp;quot;; $username = 'EB3'; $password = ''; $conn = odbc_connect(&amp;quot;Driver=/usr/sap/hdbclient/libodbcHDB.so;ServerNode=$host;Database=$db_name;CHAR_AS_UTF8=true;&amp;quot;, $username, $password, SQL_CUR_USE_ODBC); if (!$conn){ exit(&amp;quot;Connection Failed: &amp;quot;.odbc_error() . odbc_errormsg()); } $sql = &amp;quot;select * from colortbl&amp;quot;; #$sql=&amp;quot;insert into colortbl(colorid,colorname,custid)values('8912','有色','postgres')&amp;quot;; $sql = iconv(&amp;quot;UTF-8&amp;quot;,&amp;quot;gb2312//IGNORE&amp;quot;,$sql); echo $sql . '&amp;lt;/br&amp;gt;'; $rs=odbc_exec($conn,$sql); if (!$rs){ exit(&amp;quot;Error in SQL&amp;quot;); } else { $arr = array(); while ($row = odbc_fetch_array($rs)) { $arr[] = $row; } var_dump($arr); } odbc_close($conn); </code></pre>

页面列表

ITEM_HTML