Oracle Database

retrieved from scriptcase.net/blog

In the late ’70s, Lary Ellison identified a unique opportunity when he met the description of a functional prototype of a relational database, so far no company really endeavored to market this type of technology. From this, Larry Ellison created what would be one of the largest enterprise software companies in the world and also one of the databases most used and powerful market, Oracle.

Oracle was undoubtedly one of the pioneers in the world of DBMS (Database Management System Data), she created the PL / SQL and also was one of the first to create a relational database focused on the WEB, this bank was founded in 1999 with the Oracle 8i. Since the first versions to date, Oracle innovates bringing many new features and different Interest, Real Application Cluster is one of the examples of innovations that further improved support for XML and entered in version 9i as one of his greatest differentials.

The Oracle database currently trades in six versions, each containing different features and being directed according to customer needs, meet the following versions:

  • Oracle Enterprise Edition (EE);
  • Oracle Standard Edition (SE);
  • Oracle Standard Edition One;
  • Oracle Express Edition;
  • Oracle Personal Edition;
  • Oracle Database Lite

 

Read more…

Error Control in PHP

Error handling strategy is used to capture the occurrence of a situation that prevents a successful system operation. This can take place at different levels. Low level: a function can receive an unexpected parameter. At a high level, a tool can not accept certain sequence of user actions.

I think it is crucial to distinguish what is a low-level error of an error high level. Each of these errors can take a different course and be reported to the user differently too. If, for some reason, the programmer created a SQL wrong and this prevented a value to be saved in the database, it is not convenient to tell the user that the problem was in SQL, after all, the end user need not (and should not) know what is SQL. However, if the user has filled in a form field with an invalid value, it must be informed in detail about what he missed and/or how to fix.

Using exceptions natives(exception)  language PHP is a solution particularly suitable for dealing with low-level errors. In the case of high-level errors, can also be used the same alternative, although I prefer to use methods of input validation of user data and store the error messages in an array (for example). Note that usually in these cases there is no attempt to adjust the invalid value entered by the user, so is the responsibility of the user to correct the problem itself. Already low-level error, you can try to be bypassed in some way (or not).

The operation of exceptions can be relatively simple, but also lets you build solutions rather sophisticated. Don’t intend to discuss the use of exceptions. So, if you want to dig, read the manual:http://www.php.net/manual/en/class.exception.php. If you don’t like to create exception to this and that, maybe it’s a good to know the exceptions defined by SPL: http://www.php.net/manual/en/spl.exceptions.php.

A reasonable solution to error control is to create methods that return Boolean values ​​(true = worked / false = went wrong) and, optionally, the method takes an array of errors that should be passed by reference. Then, if a problem occurs, the array of errors is completed and it will return false.

For errors that should never occur (for example, an error use of a resource by a programmer), it is possible to use exceptions, but can also be used to launch the error log. This is done by the function trigger_error. The function receives a message and an error level. Levels that may be issued by the programmer are:

  • E_USER_NOTICE - When you want to send a notification to the programmer (not necessarily an error). For example: a function consumed more memory than expected.
  • E_USER_WARNING - When you want to issue a warning to the programmer (a mistake, but not too severe). For example: failing to connect to the database (for some unknown reason), but the page still can be generated with a warning to the end user.
  • E_USER_ERROR - When the error is fatal and must stop running the script (the programmer can not launch the system if an error is being caused these). For example, a method needed to receive a mandatory data type, but received another.
  • E_USER_DEPRECATED - A special type of warning to indicate that a method is depreciated (should no longer be used and/or has been replaced by a different way to perform the same operation).

There are two functions in PHP especially useful to standardize the flow of processing errors and log unhandled exceptions with try/catch. They are: set_error_handler and set_exception_handler. This makes it possible, for example, store some types of errors in a database to facilitate searches, track the amount in a given period etc..

URL Manipulation

Introduction

In web development,  is very common to use links. It is also common that the links need to be manipulated to add or remove parameters. In this post, we will see how to manipulate a link and its parameters so easy and safe.

Breaking a URL in parts

When a programmer doesn’t know the capabilities of PHP to handle URLs, it is common venture to manipulate the string with the URL directly, making operations such as checking if there is ‘?’ in the URL and get the content to the left or right, etc..

The main function to “parse” a URL and break it into parts is parse_url. This function can be used for two purposes: to get all the parts of a URL or to obtain a specific part of a URL (for example, the protocol, the domain, the query string, etc.). For all parts, just pass the URL as a parameter and don’t enter the second parameter:

For a specific part, just pass the second parameter of the function, which specifies which part is desirable. This parameter can have one of the constants:

PHP_URL_SCHEME
PHP_URL_HOST
PHP_URL_PORT
PHP_URL_USER
PHP_URL_PASS
PHP_URL_PATH
PHP_URL_QUERY
PHP_URL_FRAGMENT

Note: If you want the file name, just apply the function on the basename of $parts['path'], as an example:

Breaking the query string into parts

As you can see, the function parse_url returns the query string of the URL in the way it is and not divided into parts. To break the query string into parts, just use the function parse_str passing the query string as the first parameter and the second parameter as a vector. Vector will be populated with the variables present in the query string, so that the array index stores the variable name and each position points to the respective variable value (the value is automatically decoded urldecode). Here’s an example:


Modifying the URL or Query String

After breaking the URL and optionally the query string, just manipulate the vector $parts or $queryArray as desired. For example, let’s change the protocol from http to https, change the port from 80 to 81 and remove the parameter “x” and include the parameter “z” value “abc”:

Riding the URL with the parties

After manipulating the URL and/or query string, we now need to assemble the parts and form the URL as a string. To do this, simply use the function http_build_query to mount the query array to turn it into query string. This function now makes coding using urlencode, then you need not worry about reserved characters.

Unfortunately, http_build_url function is only available via PECL. However, it is a very simple function to implement. See below:

Now just use this function and run:

 

PHP Settings

PHP is an interpreted language that allows multiple policies are configured, both the core of the language and its extensions.

Each policy has a “mode shift” that defines where and when it can be modified. For example, some can only be set in the settings file managed by the server administrator, for security reasons, while others can be changed by the programmer in the application itself.

The modes change the policies are:

PHP_INI_USER - can be changed with ini_set, file .user.ini or in the Windows registry.
PHP_INI_PERDIR - Can be modified in php.ini.htaccesshttpd.conf or .user.ini.
PHP_INI_SYSTEM - Can be modified in php.ini or httpd.conf.
PHP_INI_ALL - can be modified anywhere.

Note: some policies belonged to a mode change by a certain version of PHP, but switched to another mode in another version of PHP. This information is displayed in the list of language policy.

 

1.0 Configuration files (php.ini)

 

phpini

 

 

The default settings are defined in the PHP files “ini” which have syntax based on simple key/value. They are loaded so that a script starts running, but the values ​​can be cached and re-loaded periodically for performance.

The file name may vary according to sapi used. For example, the default file is php.ini, but if you run the CLI sapi (PHP commands in terminal) is the sought php-cli.ini file and if it is not found, it uses the default file .

These files are in a directory server settings (on Linux are usually in the directory “/etc/”, although this site may be modified during the compilation of PHP or some alternative, although not common). Usually only the server administrator has access to these files for changes, for security reasons. This is especially useful for hosting servers, where scripts from one domain can not interfere in another.

 

2.0 Settings by Programmer

 

There are basically 3 ways programmer override the settings of PHP: through ini_set (at runtime), the .htaccess (if using Apache) or file .user.ini (an alternative created in PHP 5.3). Note that in these cases, the behavior is modified specifically for a script or set of scripts and not all PHP files, as with the php.ini file.

2.1 Using ini_set

Using ini_set, simply specify two parameters: the first is the policy name and the second is the value you want to apply to it (as a string). To get the current value of the policy, there is a function ini_get (simply enter the name of the policy). For the value of all policies, or any policies of an extension, there is a function ini_get_all. And to return the policy value to its initial value (when started the script), just use the function ini_restore stating which policy should be restored. example:

 

2.2 Using .htaccess

Use the file .htaccess for Apache servers is allowed in PHP is being used as a module. Apache must be properly configured to accept this type of file in the application directory. In this case, a policy can be defined using two syntaxes. A non-Boolean values ​​to set and another to set boolean values ​​(which may take “on” or “off”) as examples:

Note: in httpd.conf policies can be modified with php_admin_value and php_admin_flag. This can be useful to apply different settings for different directories (or different virtual hosts).

 

2.3 Using .user.ini

Use the file .user.ini is an alternative to the .htaccess, and was incorporated to PHP in version 5.3. For now, it can only be used by SAPIs CGI or Fast CGI. The syntax used in these files is identical to that used in php.ini.

The file name used for this type of configuration ( “.user.ini“) can be modified in php.ini through policy user_ini.filename. This is typically required when the application is already using that name for another purpose.

Note: it is recommended to hide access to this file, as well as (usually) is done with .htaccess to prevent it can be read by any user accessing the system.

 

3.0 Settings useful to know

  • display_errors and display_startup_errors - Indicates whether errors should be displayed or omitted (normally “on” in the development environment and “off” in the production environment).
  • log_errors - Indicates whether errors should be logged to a log file (usually “off” when “display_errors” is “on”, and vice versa).
  • report_memleaks - Indicates whether the bursts of memory should be shown/logged (usually “on”).
  • memory_limit - amount of memory reserved for PHP during script execution. Normally a simple script needs no more than 10M, but some require much more than that. The directive must be set to a reasonable value for the expanded application and, in cases of tools that require more memory. To evaluate memory usage, see the functions memory_get_peak_usage and memory_get_usage.
  • max_execution_time - Sets the maximum time the script can run before it is aborted automatically by PHP (usually “30″, but can be configured with higher values ​​for heavier tools).
  • precision - Sets the precision of decimal places for real numbers (usually 14).
  • date.timezone - Sets the default timezone of the application (eg “America / Sao_Paulo”)
  • default_mimetype - Sets the mimetype of files generated by PHP which have left with the explicit call to header (‘Content-type: …’) (eg “text/html” or “application/xhtml+xml”).
  • default_charset - Sets the default charset of the files generated by PHP which have left with the explicit call to header (‘Content-type: …; charset = …’).
  • short_open_tag - Defines whether the application will accept the abbreviated notation of PHP tags: “<?” and “?>” (recommended “on” only in closed applications whose portability is not important).
  • aps_tags - Defines whether the application will accept the notation ASP to PHP tags “<%” and “%>” (recommended “on” only in closed applications, where portability is not important).
  • register_globals - Defines whether the application will create global variables to values ​​derived from EGPCS (Environment, GET, POST, Cookie, Server). It is strongly recommended to use “off” because it is a deprecated feature which makes the application more prone to security breaches.
  • magic_quotes_runtime and magic_quotes_gpc - sets whether addslashes automatically applied on the data submitted. It is strongly recommended to use “off” because it is a deprecated feature and featuring a performance disadvantage.
  • arg_separator.output - Separator used by standard PHP functions that build URL. It is recommended “&”, especially for applications XHTML).
  • session.auto_start - Automatically log (usually “off”)
  • session.use_cookies - Indicates whether sessions can use cookies to store session keys (recommended “on”).
  • session.use_only_cookies - Indicates whether sessions can only use cookies to traffic session keys, rather than inform them via GET (it is strongly recommended “on” for security reasons).
  • session.use_trans_sid - Indicates whether sessions can use the mechanism of “transparent sid” to travel the session keys (data passed by GET) (it is strongly recommended “off” for security reasons).

Problems with charset? Never again!

In this article we will see how to use UTF-8 at all and never see characters being displayed wrong.

1.  Save the source code in UTF-8

First of all, choose a good source code editor that allows you to define which encoding used in saved files. Normally this is the editor settings or options of saving time. If you use text mode editors, you may need to configure it in the settings of the terminal command (gnome-terminal, xterm, etc.).

Note: some publishers have option to save the file with the BOM. It is recommended that doesn’t include these bytes, because they can cause unexpected behavior in PHP. For example, you will not be able to call functions such as header or use the namespace feature, which requires that the namespace declaration is the first thing in the script.

2. Tell the browser that you use UTF-8

When a PHP file and generates a HTML is sent to the browser, along with the file go to header (HTTP protocol), where you specify the file type and encoding. If you don’t report it explicitly in your code, your HTTP server (for example, Apache) will send this file with a mime-type pattern (usually “text/html”) and a default encoding (usually “ISO-8859-1 “).

To change this header explicitly, and properly inform the mime-type and encoding of the document you are creating, use the header function, passing the policy “Content-type” as such:


If the file is of another type, just change the mime-type to the corresponding type (eg “text/css”, “text/xml”, “application/xhtml+xml”, etc).

However, the files aren’t always generated via PHP. There are static HTML you need to inform the HTTP header with the mime-type and correct coding. In this case, there is an alternative that is using the meta tag with the attribute “http-equiv” (equivalent HTTP). With it, you can “simulate” HTTP header by the contents of the HTML document. This is done as follows:

In HTML 5, it was simplified:

If you use XML or XHTML, remember to inform the UTF-8 encoding in the XML header:

 

 3. Communicate with the BD via UTF-8

For information to be trafficked between PHP and the database using UTF-8, you must declare this encoding logo that connects to the database. This varies from bank to bank, but let’s see some common examples:

MySQL (PDO):


MySQLi:

MySQL (functions):

Note: the connection to MySQL functions are deprecated. Prefer to use PDO or MySQLi.

PostgreSQL (PDO):

 PostgreSQL (functions):

 

 4. Create your database in UTF-8
The text fields stored in databases also need a character encoding. If it isn’t defined when you create the field, the default encoding is taken from the table or from the database. To set a default encoding of a database, use the command:
MySQL:

 PostgreSQL:

 5 Remember to specify the UTF-8 which you can

Some functions in PHP receive as parameter encoding to be considered. Some of the most important things that should be highlighted are: htmlentities and htmlspecialchars.

Furthermore, when performing operations with regular expressions PCRE, remember to use the modifier “u” at the end of the expression, indicating that it is UTF-8, as an example:


An important set of functions takes into account the location (with encryption) to function. So it is also important to properly set the locale to locale UTF-8:

Remember that the location depends on the server and the name used may vary.

Conclusion:
Taking the necessary steps, you can use UTF-8 with no big problems at all layers of their system: in HTML, PHP and database. Problems with charset? Never again!

Compound Triggers in Oracle 11g

From Wikipedia: “A database trigger is procedurale cod that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database. For example, when a new record (representing a new worker) is added to the employees table, new records should also be created in the tables of the taxes, vacations and salaries.”

Oracle 11g offers a new twist on triggers, the compound trigger, a trigger that can act both before and after an update, insert or delete has occurred. This makes possible the ability in one trigger to perform processing similar to a stored procedure without having to write such a procedure to call from a traditional trigger. Compound triggers can be used to avoid the dreaded mutating table error or to process and accept or reject updates to a table based upon desired criteria. Before we look at such an example a description of how a compound trigger is constructed is in order.

Compound triggers can have up to four sections:

  • the BEFORE section
  • the BEFORE EACH ROW section
  • the AFTER EACH ROW section
  • the AFTER section

At least two of the sections must be included (including only one of the four would result in a traditional trigger) and it does not matter which two of the sections are used. For example such a trigger can include a BEFORE EACH ROW section and an AFTER section; the two sections need not be ‘matched’ (BEFORE, BEFORE EACH ROW, for instance). Also the COMPOUND TRIGGER STATEMENT must be included so Oracle will recognize the above four constructs and treat them accordingly. The general syntax is:

Since compound triggers are relatively new and many may not have had the opportunity to write or use them I have provided a working example. Setting the stage for this trigger, HR has set a restriction on the size of a raise to be given; based on the department the raise cannot exceed 12 percent of the department average salary. A compound trigger can be used to process the raise amounts assigned. Such a compound trigger is shown below, along with several ways of executing the raises:

PHP Oracle – Scriptcase 7 is out!

PHP Oracle – The new version  of Scriptcase 7 came out in January!

With it came many improvements like Dynamic Group By, HTML 5 Charts, Integration with Social Networks, Upload multiple files, Export PDF in Forms, LDAP security, Menus for mobile devices and more!

See a list with some of the new features:

 

  • SQL PDO Drivers (MySQL, PostgreSQL, SQLServer)
  • Toolbar option
  • Mobile menu support
  • Integration: PayPal, Facebook, Google+, Twitter
  • Grid Ajax events
  • PDF export on forms
  • Progress Bar/Drag’n Drop Upload
  • Multiple Upload
  • HTML5 Charts
  • Javaless PDF generator
  • Reworked GroupBy with Multiple Rules
  • Percent(%) field
  • Single-record-detail on master/detail
  • LDAP Support for security module
  • Scriptcase Macros improvement
  • New Scriptcase Macros created

Check more about Scriptcase 7 at: www.scriptcase.net

PHP Oracle Blog

PHP Oracle – Selecting from the DUAL Table

PHP Oracle – Selecting from the DUAL Table

DUAL is a table automatically created by Oracle Database along with the data dictionary. DUAL is in the schema of the user SYS but is accessible by the nameDUAL to all users. It has one column, DUMMY, defined to be VARCHAR2(1), and contains one row with a value X. Selecting from the DUAL table is useful for computing a constant expression with the SELECT statement. Because DUAL has only one row, the constant is returned only once. Alternatively, you can select a constant, pseudocolumn, or expression from any table, but the value will be returned as many times as there are rows in the table. Refer to “About SQL Functions” for many examples of selecting a constant value from DUAL.

Note:

Beginning with Oracle Database 10g Release 1, logical I/O is not performed on the DUAL table when computing an expression that does not include the DUMMY column. This optimization is listed as FAST DUAL in the execution plan. If you SELECT theDUMMY column from DUAL, then this optimization does not take place and logical I/O occurs.

The dual table “works” almost just the way any other table works: it is a table from which you can select records.

This means, for example, you can describe the table. Here, in SQL*Plus:

So, the table has one column, named dummy which is a varchar2(1).

The table has, by design, one record (at least if nobody fiddled with it):

So, in order to get the same behaviour with dual2 as you have with dual, you have to insert one record into dual. Better yet, create it with a create table as select (ctas):

Now, your query works:

Earlier, I said that dual almost works like any other table. So, when does it not work like any other table?

It behaves differently, if no value from the table itself is selected. Again, with your queries, I let Oracleexplain them …

… in order to see how the table is accessed:

It can be seen that the statement does a full table access on dual2.

Now, same thing with dual:

This is where the dual table behaves differently: the value of dummy is not needed, so a fast dualoperation is executed, in order for the instance not to read the actual value on the disk.

 

PHP Oracle Blog

PHP Oracle – Oracle Resources Consolidation and Cloud Computing for SPARC Supercluster

PHP Oracle – Oracle Resources Consolidation and Cloud Computing for SPARC Supercluster

 

Oracle Corporation announced new software enhancements that were implemented for the SPARC Supercluster system, allowing customers greater consolidation of any combination of enterprise databases, middleware and mission-critical applications. All this being done in a single system and implementing fast, secure services in self-service cloud computing.

The SPARC Supercluster is able to achieve a rate 10x higher in the consolidation of applications using the new virtualization overhead zero layered together to offload functions (charge transfer), the storage server Oracle Exadata Database Machine and an extremely efficient network.
Resources Offered to Customers of SPARC Supercluster

The SPARC system SuperClusster enables its customers to quickly deploy applications and mission-critical multi-tenancy, without virtualization overhead from the use of isolation capabilities with reference to Oracle Solaris Zone. In addition, customers can virtualize Oracle databases run on Exadata Database Machine X3 Storage Server with Solaris Zones, with the intention of ensuring the delivery of safe and isolated from the database in the cloud.

There will also be the possibility of implementing various fields of enterprise applications in each computing node SPARC Supercluster, to maximize the consolidation and flexibility in use of cloud computing. As a result, customers can also reallocate the CPU and memory resources in existing fields and areas of SPARC Supercluster, aiming to meet the needs of changing workloads.

Implementation of Insurance Services with Flexibility and Faster

The SPARC Supercluster with Oracle Enterprise Manager 12c provides an up to 10x faster provisioning of cloud services, in relation to multi-tenancy applications in relation to manual provisioning, using various tools, as well as an implementation up to 32x faster than one instance of Oracle Database compared to the installation manual. In addition, the SPARC Supercluster provides a comprehensive management solution lifecycle cloud with Oracle Enterprise Manager 12c.
Maximum Efficiency, Decrease Costs and Increased Performance

Compared to integrated systems of customers, the SPARC Supercluster features a 5x return faster and reduce the time since its installation process to production with client systems. Previously, this process took months to complete and can now be done in weeks. We also observed a 10x better performance of data warehouse by combining the latest servers Oracle Exadata Database Machine X3 Storage Servers SPARC Supercluster incorporated into the platform.

Remember that virtualized applications that run quickly and efficiently implementations bare-metal hypervisor using the embedded processor SPARC T4. Customers reduce operating costs by consolidating Oracle Solaris 10 and earlier environments with high performance and maximum efficiency of the SPARC Supercluster, without changing the day to day operations of these environments.

SPARC Supercluster clients also have access to Oracle Premier Support, including Oracle Platinum Services, which offers customers a configuration system designed Oracle support 24 x 7 remote monitoring of failures, and better response times and restoration industry . There is also a presentation of quarterly patch updates directly implemented in systems with high availability in mission-critical environments.

 

Know more:

Oracle Corporation – SPARC SuperClusterhttp://www.oracle.com/us/products/se…88105-ptb.html

 

PHP Oracle Blog

PHP Oracle – PHP 5.5.0 Alpha2 released

PHP Oracle - PHP 5.5.0 Alpha2 released

 

PHP Oracle Blog – The PHP development team announces the immediate availability of PHP 5.5.0alpha2. This release adds new features and fix some bugs from alpha1. All users of PHP are encouraged to test this version carefully, and report any bugs in the bug tracking system.

THIS IS A DEVELOPMENT PREVIEW – DO NOT USE IT IN PRODUCTION!PHP 5.5.0 Alpha 2 comes with new features and improvements such as (incomplete list) :

  • Support for using empty() on the result of function calls and other expressions,
  • Systemtap support by enabling systemtap compatible dtrace probes on linux,
  • Optimized access to temporary and compiled VM variables. 8% less memory reads.

Please, note that this alpha version also introduces the ext/mysql depreciation.

You can read the full list of changes in the NEWS file contained in the release archive.

For source downloads of PHP 5.5.0 Alpha 2 please visit the download page, Windows binaries can be found on windows.php.net/qa/.

Thank you for helping us making PHP better.