Penggunaan fungsi CCSID pada PHP

Penggunaan fungsi CCSID pada PHP
One of the open source components we’ve built at Seiden Group is a new extension to enhance PHP’s integration with IBM i.

Although most business requirements are met by the existing ibm_db2 and PDO_ODBC extensions plus the PHP Toolkit, the new php-ibmi makes it easier to accomplish several (formerly) difficult or impossible tasks—especially for tool vendors, and when troubleshooting.

We’ve built six functions thus far, with the possibility of more in the future. Let us know what you think.

What can I do with the IBM i extension?

php-ibmi currently has six  functions:

  • ibmi_get_job_ccsid()
  • ibmi_get_pase_ccsid()
  • ibmi_cl_exec()
  • ibmi_cl_system()
  • ibmi_cl_passthru()
  • ibmi_stat()

Detailed documentation can be found on the php-ibmi extension Github page.

Let’s take a quick look at what each of these functions can do.

Character set help

Our support team uses the ibmi_get_pase_ccsid() and ibmi_get_job_ccsid() functions when answering questions about encoding and character sets.

To show information about character sets and encoding, we created a PHP script called encoding.php:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<PRE>

<?php

echo"LC_ALL: ".getenv("LC_ALL")."\n";

echo"LANG: ". getenv("LANG")."\n";

echo"FastCGI CCSID: ".getenv('CCSID')."\n";

if (extension_loaded("ibm_db2")){

        echo"i5_override_ccsid: ".ini_get("ibm_db2.i5_override_ccsid")."\n";

} else{

        echo"ibm_db2 extension not loaded"."\n";

}

if(extension_loaded("ibmi")){

        echo "PASE CCSID: ".ibmi_get_pase_ccsid()."\n";

        echo"Job CCSID: ".ibmi_get_job_ccsid()."\n";

}else{

    echo"ibmi extension not loaded"."\n";

}

?>

</PRE>

Sample output:

LC_ALL:EN_US

LANG:

FastCGI CCSID:1208

i5_override_ccsid:0

PASE CCSID:1208

Job CCSID:37

Run CL commands directly in your PHP job

The functions ibmi_cl_exec(), ibmi_cl_system(), and ibmi_cl_passthru() provide the power to execute a CL command in the same job that runs your PHP code.

Why does this matter? Let’s say you wanted to change some job attributes by running CHGJOB. If you used a Db2 stored procedure or the toolkit, the command would run in the Db2 or toolkit job. If you used the system command, it would run in a different PASE job spawned to run the command. Because CHGJOB’s changes would apply to the spawned job instead of the PHP job, they wouldn’t stay with the PHP job.

The IBM i extension adds APIs (analogous to PHP’s exec, system, and passthru functions for normal PASE commands) to run CL in the context of the PHP job. A similar feature was recently introduced by IBM for the bash shell.

Get IFS file information

ibmi_stat() gets information about an IFS file. One useful item is the CCSID of the file. This function is akin to the ILE stat() function.

Where can I get it?

New installations of CommunityPlus+ PHP have included php-ibmi by default since November 2021.

If you have an existing install without this extension, run yum install php-ibmi. With site-specific custom configurations, yum won’t install the configuration file in conf.d automatically. In that case, copy /QOpenSys/etc/php/conf.d/99-ibmi.ini to your site’s extension INI directory (for example, /www/sitename/phpconf/conf.d).

Those wishing to view PHP IBM i extension source code, or even build from source, can find our PHP IBM i extension on GitHub.

We’d like to hear from you about what you’d like to see in this extension; anything on the i you wish you could do from PHP?