LoginSignup
1
0

PHP oci_connect SELECT テンプレ Smarty .tplで出力

Posted at

■ 開発環境

・PHP7.4
・Smarty 2.xxx
・RedHat7.9
・oracle 19

■ ソース概要

・OCIで、oracleへ接続
・接続後、SELECT文で値を配列へ格納
・上記で取得した値を、foreachで回して、別々の配列へ格納

--- ここから Smarty .tpl
・PHP側で取得した値を出力

■ PHPソース

php index.php

	function GET_KASOU_KUBUN()
	{

		// OCI
		$conn = oci_connect(DB_USER, DB_PASSWORD, DB_CONNECTION_STRING, DB_CHARSET);

		if (!$conn) {
			$e = oci_error();
			self::fnDispError(DB_ERROR, $e['message'], true, DEBUG_MODE);
		}

		$sql = "SELECT カラム01, カラム02 FROM テーブル01 WHERE カラム01 < 3";
		$stid = oci_parse($conn, $sql);
		if (!$stid) {
			$e = oci_error($conn);
			self::fnDispError(DB_ERROR, $e['message'], true, DEBUG_MODE);
		}

		$r = oci_execute($stid);
		if (!$r) {
			$e = oci_error($stid);
			self::fnDispError(DB_ERROR, $e['message'], true, DEBUG_MODE);
		}

		$nrows = oci_fetch_all($stid, $res, null, null, OCI_FETCHSTATEMENT_BY_ROW);

		$arr_Kasou_k = array();
		$arr_Kasou_k_Name = array();

		$idx = 0;
		foreach ($res as $k_val) {
			$arr_Kasou_k[$idx] = $k_val['カラム01'];
			$arr_Kasou_k_Name[$idx] = $k_val['カラム02'];
			$idx += 1;
		}

		if (
			$nrows > 0
		) {
			//Ut_Utils::printR($res);
			$this->arrKsou_K = $arr_Kasou_k_Name;
		}

		oci_free_statement($stid);
		oci_close($conn);
	}

■ Smartyソース

Smarty index.tpl

     <tr>
            <th class="alignC w_20">
            火葬区分
            </th>
            <td colspan="7">
            <!--{html_radios name="$key1" options=$arrKsou_K selected=$kasou_idx|default:0}-->
            </td>

     </tr>

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0