Publish your local folder over internet

Using HFS application  you can download it from here:

Steps to publish your files
  1. Download HFS (from here)
  2. Right click desired folder to publish
  3.  Check if it's real or virtual folder
  4. To change port from 8080 to 280
    1. in Home screen of HFS 
    2. upper left , click Port:8080
    3. change it to 280
  5. You are done !

Parsing JSON Manually in oracle database

Json  data is very useful when working with web services.

Here's an example of  JSON structure :

To extract data from json use the follwing function:


CREATE FUNCTION PARSE_JSON ( P_Text  IN VARCHAR2,
                                 P_Field IN VARCHAR2,
                                 P_Occur IN NUMBER) RETURN VARCHAR2 IS
 V_Text_Ready    VARCHAR2(2000);
 V_Elemnt_Occur  NUMBER :=P_Occur;
 V_Elemnt_Name   VARCHAR2(100) :=P_Field;
 V_Elemnt_Value  VARCHAR2(200);
BEGIN
  --------------
  V_Text_Ready := REGEXP_SUBSTR( P_Text , '{(.*?)\}',1,V_Elemnt_Occur);
  V_Text_Ready := REGEXP_REPLACE(V_Text_Ready , '({|"|}|\]|\[)+');
  V_Elemnt_Value := REGEXP_REPLACE(REGEXP_SUBSTR(V_Text_Ready, V_Elemnt_Name||':[^,]+', 1 , 1), V_Elemnt_Name);
  --------------
  RETURN ( REGEXP_REPLACE(V_Elemnt_Value,':'));
  --------------
  EXCEPTION
    WHEN OTHERS THEN
      RETURN (NULL);
 END PARSE_JSON;


Calling Oracle Procedures from PHP

Using Oracle Functions or Procedures can be used to insert /update/delete data from oracle database.

While creating function ADD_INVOICE to insert data in AR_HEADER and AR_LINES,
I found when calling it from TOAD it works fine and insert data in the two levels (HEADER and LINES).

When using PHP it only insert data in one level (HEADER) only.

After some search , I got the concept of calling stored procedure using PHP.
So, I converted the preceding function (ADD_INVOICE ) to procedure which holds an OUT parameter.

Then  when calling it, the insert was successfully in the two levels (HEADER and LINES).

here's the PHP get code :


<?php
    //Connect to oracle database 
    $db=oci_connect('pos','pos','prod', 'AL32UTF8');
    
    $query = " DECLARE  BEGIN ADD_INVOICE(:message); END;";     
    $stmt =oci_parse ($db , $query);  
    // Bind the output parameter
    oci_bind_by_name($stmt,':message',$message,32);    
    // execute query
    oci_execute($stmt); 
print "$message\n";
UPDATES:
 The preceding  $query in green , must be written in one line , to avoid erros!
Also when receiving JSON  using $_POST methods , it's automatically add back slash to every character.

I send json_text : [{ "product_id": "60402", "price": "20.0", "tax_rate": "0.0" , "qty": "1", }{ "product_id": "60302", "price": "60.0", "tax_rate": "5.0" , "qty": "1", }]

It's converted to: [{ \"product_id\": \"60402\", \"price\": \"20.0\", \"tax_rate\": \"0.0\" , \"qty\": \"1\", }{ \"product_id\": \"60302\", \"price\": \"60.0\", \"tax_rate\": \"5.0\" , \"qty\": \"1\", }]

So We use Oracle REPLACE function to remove back slash  ,then parse json.

Connect PHP and Oracle database 10g

I posted before how to create APIs (Web Services) from Database 10g using PLSQL Gateway in this post.

When Android developer reads API , Arabic fonts was not complete when using FLUTTER, but when he using Android Studio he reads without any losing characters.

I found using php server , it works fine.

Here are steps to create your first APIs to connect PHP and ORACLE 10g together:
1#  HR schema is used in the following example
2#  Download this Github repository from  here (It includes AppServ and API Folders) APPSERV another link
3# Install AppServ to C:\AppServ
4#Extract ora_php-master.zip to C:\AppServ\www
5# Rename C:\AppServ\www\ora_php-master to  C:\AppServ\www\api
 Now your folders and files  should looks like this:

6# Config Folder: Contains database.php ,

<?php

class Database{

 // specify your own database credentials

    private $host     = "localhost"; //DataBase Server

    private $db_name  = "PROD";    //DataBase Name

    private $username = "hr";            //User Name, which We'll Create API for

    private $password = "hr";            //User Password

    public  $conn;                              //Public Varaible
// get the database connection
    public function getConnection(){
  $this->conn = null;
  try{
   $this->conn = oci_connect($this->username, 
                             $this->password, 
           '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
                                      (HOST = '.$this->host.')
                 (PORT = 1521)) 
               (CONNECT_DATA = (SERVICE_NAME = '.$this->db_name.') 
                               (SID = '.$this->db_name.')))' , 'AL32UTF8');
   }
  catch(Exception $exception){
   echo "Connection error: " . $exception->getMessage();
   }
   return $this->conn;
   }

7# Objects Folder : Contains all Users, if  we do have other users .


8# User Folder : For every object we create folder contains all types of API  (GET, PUT, POST....)


9# To Test API : goto http://localhost/api/user/read.php
URL consists of : Machine_Ip/API_Folder(Which was ora_php-master)/APIS_FOLDER(USER)/API_METHOD(read.php or search.php?id=107)

10# Done , Now you can connect to database from any machine, Android, iOS etc......

UPDATE #1
You may face an error  like Call to undefined function oci_connect .

Here's how to fix it :
# You need to enable OCI for php
# Edit php.ini

# enable extension=php_oci8.dll
BEFORE : ;extension=php_oci8.dll
AFTER    : extension=php_oci8.dll

# Restart AppServ .

UPDATE #2

To make sure OCI works , Open browser and goto  http://localhost/phpinfo.php
it must looks have oci like that :




UPDATE #3

Connecting to remote DataBase is some tricky , You just add connection string  when calling OCI_CONNECT , here's a full example :


<?php
//Connect String
$db="(DESCRIPTION=
     (ADDRESS_LIST=
       (ADDRESS=(PROTOCOL=TCP)
         (HOST=192.168.1.25)(PORT=1521)
       )
    )
        (CONNECT_DATA=(SID=HR))
 )";

//Connect to DB

$conn = oci_connect('hr','hr',$db); 


//Run a sample query

$qry = oci_parse($conn, 'select SYSDATE from DUAL');


if (!qry){

    echo "Not connected";

}else{

    echo "Connected";

}

UPDATE #4

If you still cannot see OCI8 in http://localhost/phpinfo.php , here's final steps :

1# download  oracle instant client (instantclient-basic-win32-10.2.0.5) from here 

2# Extract all contents to the zipped file to :
   - C:\AppServ\Apache2.2\bin
  and
  - C:\AppServ\php5\ext

3#  Edit System Variables PATH 
  add C:\AppServ\php5\ext  at the end of existing text

4# Restart the Apache server

5# You are done !

Create nested JSON Array

To query all EMPLOYEES below the main Departments , and get the result in JSON format .

Connect using SCOTT user

Following are steps:
#1 Create GET method
Type : QUERY
Pagination Size: 0


GET method

#2 Add the following code :


SELECT G.Deptno,
       G.DName,
       CURSOR ( SELECT V.Empno, 
                       V.Ename
                FROM   EMP V 
       WHERE  V.Deptno = G.Deptno )  EMPLOYEES
FROM   DEPT   G
Here's the output in PLSQL/Develoepr

Share Folders using FTP builtin windows service

File Transfer Protocol (FTP) is an easy way to access files remotely in the same network or over the web too.

Windows Server 2003 has a built-in feature to enable FTP, here's how to activate FTP.

Before we start we'll need Windows Server 2003 ISO .

  1. Go to CONTROL PANEL, Add Or Remove Programs
  2. On the  left side , click: Add/Remove Windows Components
  3. Select : Application Server ,
  4. Click  Details
  5. Select Internet Information Services (IIS)
  6. Click Details
  7. Select File Transfer Protocol(FTP) Service
  8. OK
  9. Click Next
After  previous steps are done, complete as followd:
  1. Go to CONTROL PANEL, Administrative Tools
  2. Click Internet Information Services (IIS) Manager
  3. On the left tree side, expand FTP Sites  node
  4. Right Click  Default FTP Site,  Choose New , FTP Site...
  5. Choose IP Address : 192.168.1.92
  6. In The  Path page, Click Browse to choose desired Folder you want to share it (Say it's srvr_dsk)
  7. Open Browser go to : FTP://192.168.1.92/
  8. You're done !

Share folders using Apache Tomcat

When it comes to accessing images, files and other media through internet, There are many solutions especially when using ORACLE  APEX.

But when using Oracle 10g it's bit hard, so I used  Apache Tomcat.

Steps to share folder and access it using http:// :

  1. Downlaod and install Java6 Update 20 from here: https://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html
  2. Download and install Apache Tomact from here: http://tomcat.apache.org/
    1. Remember well the PORT : 8080  or any other one
    2. Remember well the user: ADMIN
    3. Remember well the user Password: ******
  3. Suppose you have installed Apache Tomcat in the following path: C:\Program Files\Apache Software Foundation\ :
    1. Go to : C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\
    2. Edit web.xml   <param-name>listings</param-name> <param-value>false</param-value>
    3. Change false to true :
      <param-name>listings</param-name> <param-value>true</param-value>
  4. Go to : C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT
    1. Remove all contents
    2. Place here all your folders, files to make it shareable
  5. Restart Apache Tomcat
  6. Open Browser and Go to  : http://127.0.0.1:8080/
  7. you're done
UPDATE : To share any folder without copying it to ROOT folder :
  1. Go to C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf
  2. Edit server.xml
  3. Add the following line :

<Context docBase="c:\insight_dsk" path="/images" reloadable="true" source="c:\insight_dsk"/> 
c:\insight_dsk : Folder you want to share it
images     : Alias appears on the web page

4. Restart Apache Tomcat

To Display folder files goto:   http://127.0.0.1:8080/images

Remove unused Layouts in Oracle Apex

 Tables used : APEX_XXXXXXX.WWV_FLOW_REPORT_LAYOUTS APEX_XXXXXXX.WWV_FLOW_SHARED_QUERIES use the following query to delete unused Layouts. ...