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 !

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. ...