Wednesday, October 31, 2012

Differences MySQL with Oracle (PART 2)


In previous articles we have discussed the three differences between MySQL with PHP. In this article we will discuss the continuation of the differences between MySQL with PHP.

4. Free Statement

            In Mysql syntax for free statement:

                        mysql_free_result(statement);

            While at Oracle syntax for free statement:

                        OCIFreeStatement(statement);

5. Obtain the number of rows

            In Mysql syntax for Obtain the number of rows:

                        mysql_num_rows(statement);

            While at Oracle syntax for Obtain the number of rows:

                        OCIRowCount(statement);

6. Create array

            In Mysql syntax for create array :

                        mysql_fetch_array(statement, tipe array);

            While at Oracle syntax for create array:

                        OCIFetchInto(Statement, array_result,[mode]);

           
           




Tuesday, October 30, 2012

Differences MySQL with Oracle (PART 1)


Some differences between Mysql to Oracle, namely:

1. Connection

In Mysql syntax for connection:    
       
                mysql_connect(“host”,”username”,”password”);

                While at Oracle syntax for the connection:

                                OCILogon(username,password, [ORACLE_SID]);

2. Closing the connection

In Mysql syntax to close the connection:

                                mysql_close(connection_variabel);

While at Oracle syntax to close the connection:

                                OCILogoff(connection_variabel);

3. executing Query

In Mysql syntax to execute the query is:

                        Mysql_query(query);

            While at Oracle syntax to execute the query is:

                        OCIParse(connection_variabel,query);


Monday, October 29, 2012

Parameter Settings in the PHP.ini

The parameters that need to be considered are:

1.  Display_errors

            Display_errors is used to display an error because error of the source code that we make, if set display_errors is ON then the error will be displayed on the webbrowser, if set OFF then the error will not be displayed on the webbrowser.

Syntax:

                display_errors = on

2. Register_globals

            Register_globals if we set ON the variable to be sent not have captured the destination file. Register_globals if we set off then all sent through post method, get, cookies, session etc must be recaptured in the destination file using $ _POST, $ _GET, S_COOKIES, $ _SESSION etc.

Syntax :

            register_globals = on


3. Error_reporting

            Error_reporting is used to display error is very sensitive to the error source code is made.

Syntax :

            error_reporting= E_ALL & ~E_NOTICE & ~E_STRICT



Sunday, October 28, 2012

Array in PHP


Elements is the name of the data on the array and the location of each of the elements indicated by an index. Array starting at index 0. Array has two boundaries, the lower limit and upper limit.

The dimensions of the array can be one or more dimensions. Some examples dimensional array:

a. One-dimensional Array (representing vector shapes)
b. Two-dimensional array (representing the matrix form)
c. Three-dimensional array (representing the shape of the room)

Writing array syntax:

Array[];

$variabelname=$array(“elemen0”,”elemen1”,”elemen2”,”elemen..n”);

Example:

1. The first form of array declaration

$flower[ ]=”Roses”;
$flower[ ]=”Orchid”;
$flower[ ]=”Jasmine”;
$flower[ ]=”Sunflower”;

print($flower[2]);

The result is Jasmine

2. The second form of array declaration

$flower=array(“Roses”,”Orchid”,”Jasmine”,”Sunflower”);

Print($flower[1]);

The result is Orchid

Saturday, October 27, 2012

Create Process Delete Data


            Having previously discussed the action to edit the data, the script is the script divbawah to delete the selected data.

This is a script to delete data:


<?php
include "koneksi.php";
$hapus=mysql_query("delete from produk
 where kodeproduk='$_GET[id]'");

 include "viewproduk.php";
?>



Delete process above is based on the kodeproduk item we choose to delete. hopefully useful ^ ^

Friday, October 26, 2012

Create Process Edit Data


        When you have finished editing the form, the next step is to create a script to the editing process.

Here's the script to the editing process:


Thursday, October 25, 2012

Create Form EDIT


        In this article we are going to add the delete to delete the data in the table.
The first step is to add a column to the viewproduk.php as the process by which the process will contain edit and delete.

Script to edit the data in the table:




After creating the form for editing, the next article will discuss the process of editing.

Wednesday, October 24, 2012

Create Script to Display Data


         After finished creating the form plus additional data and process the data we will create a page to display all the data in the table and adding the data is managed. 

The script is saved as viewdata.php

Script to display all of the data Produk table:


Tuesday, October 23, 2012

Create Process Add Data

      Once we create a form to add data on the product, the next step is to create a script for the process of adding data to the database.

Here is a simple process of adding the data in the products table:



The next step is to look after the data has been added which will be discussed in the next article ^ ^.

Monday, October 22, 2012

Make Adding Form Data


       In this article we will discuss about creating a form to add data to the table that we have created in mysql. In this discussion we are still using the sales database and table to be used is the Product table.

The following script to add data in the Product table:



For further discussion we will discuss the process of adding data to the database

Sunday, October 21, 2012

Implementation Session With Cookies


       In this discussion we will discuss a script to count the number of visits by using session cookies are implemented. The trick is to add the script below on checksession.php


If(!isset ($_COOKIE[“counter”])){
      $i=0;
}
Else{
      $i=$_COOKIE[“counter”];
      $i++;
      Setcookie(“counter”,$i,time()+3600*24*365);
Echo “you've already visited “.$i.”times”;

Enter the above script on checksession.php

Saturday, October 20, 2012

Query SQL UPDATE and DELETE


UPDATE command is used to change the fields in a table.

Example:

Update the contents of the Produk table.

$query=”Update Produk SET namaproduk=’sower’,harga=3000,diskon=0 where kodeproduk='12345'”;

            $command=mysql_query($query);

DELETE command is used to delete a column from a table.

Example:

Deleting columns Diskon in the table Produk.

            $query=”Delete diskon from Produk where KodeProduk=’12345’”;
     $command=mysql_query($query);

Friday, October 19, 2012

Query SQL SELECT and INSERT


SELECT command in SQL is used to display the field in the table that we want.

1. Command to display all the existing columns in a table.

            Example :

            Display all the existing columns in Produk table.

      $query=”Select * from produk”;

      $command=mysql_query($query);

2. Command to display a particular column in a table.         
 
Example:

            Display Nama Produk and Harga

            $query=”Select NamaProduk,Harga from produk”;

      $command=mysql_query($query);


INSERT command in SQL is used to enter the field in the table.

Example:

Insert  field in the Produk table:

$query=”insert into (KodeProduk,NamaProduk,Harga,Diskon) values(‘12345’,’Soap’,4000,10)”;

            $command=mysql_query($query);

Thursday, October 18, 2012

The functions available in MySQL (Part 2)


      In previous articles have discussed four functions that exist in mSQL and at this time we will discuss the four other functions that exist in MYSQL.

5. mysql_fetch_array
            Used to produce an array where each column will be stored twice on each result array where the first store the index numbers starting from number 0 and the second column store index.
            Example :
            mysql_fetch_array($query);

6.mysql_fetch_rows
            Used to produce an array that contains the column.
            Example :
            mysql_fetch_rows($query);

7. mysql_num_rows
            Used to get the number of rows from a select query is executed.
            Example :
            mysql_num_rows($queryselect);

8. mysql_nums_fields
            Used to get the number of columns from a select query is executed.
            Example :
            mysql_num_fields($queryselect);

Wednesday, October 17, 2012

The functions available in MySQL (Part 1)


The functions in MYSQL which we use to connect and manipulate data in the database are:

1. mysql_connect
Used to open a connection to a mysql database
            Example:
                mysql_connect(“localhost”,”root”,””);
                  Host                user      password

2. mysql_query
Used to execute commands on the table.      
Example :
            mysql_query(“Select * from produk”);
                             query

3. mysql_select_db
Used to select the database to be used.         
Example :
            mysql_select_db(“penjualan”)
                     databasename

4. mysql_close
            Used to close the connection with mysql.
            mysql_close($koneksi);
                  connectionvariabel

Tuesday, October 16, 2012

Create Logout


To end the session or delete session then this script from logout.php

Script Logout.php :


Monday, October 15, 2012

Create Cek from Login Action with Session


To see the results of the session that we created then we have to make ceksession.php
Syntax :



Sunday, October 14, 2012

Create Login Action with Session


Previously we've made a login .. this time we will create a login action of the form that we have made to implement the session.

Script login action:


Then save it as loginaction.php

Saturday, October 13, 2012

Create a form login


At this time we will make a login form.

Script to create a login form:





Then save it as login.php

The results appear in the webbrowser:


In the subsequent discussion we will create a login action.

Friday, October 12, 2012

Create Cookies


       Command Cookies must be performed first as the first command in the script as well as in our session. Written on client webbrowser with the function syntax:

            setcookies(stringname, stringvalue, intexpire);

Example :

            setcookies(“username”, “membername”, time()+3600);

      Syntax will make cookies with a username that has values ​​and attributes Membername expire, which means that the cookies have the time after 3600 seconds and 3600 seconds it will disappear.

Thursday, October 11, 2012

Create Session


            Creating session function which will check whether the existing session id or not the function is as follows:

session_start();

   Next is to create a global register that functions allow the server to remember the identity of the user, the user must be registered to use the function:

session_register();

In making the registers can also use $_session or $HTTP_session_vars

example :

            $username=”membername”;
      $session_register (“$username”)
      $_session[$username]=”membername”;
      $HTTP_session_vars[“username”]=”membername”;

If you wish to register more than one session variables:

            $session_register (“var1”, “var2”, “var..n”);
     
To remove or end the session function :

            session_unregister();
      session_destroy();
      session_unset();  

but if we use the $_session or $HTTP_session_vars then the function is used :

            unset($HTTP_session_vars[“sess_var”]);
     

Wednesday, October 10, 2012

Session and Cookies


     Session and Cookies are often used to access web pages that provide the member or associated facilities with access to the database by the member (registered members). Benefits of Session and Cookies is to remember the identity of the user and displays information that can be accessed where the procedure is performed once at the beginning of the process (login) and when user logout the user identity will be forgotten in order not to be used by other people.

      The identity of the member shall be stored so that when access to the server it is not recorded as a new visitor.

A. Session

     Session is used for accessing the user information will be safe. Data from the user session will be created when the user visiting the website and logging on.


B. Cookies

    Cookies are one of the same facility with the session where the difference lies in the recording where the recording on cookies to remember do webbrowser


Tuesday, October 9, 2012

Building a Database on MYSQL


A. Creating Database

             The format of writing to make databsae with manual writing format is:


             CREATE DATABASE <namedatabase>

             Example: Create DATABASE Penjualan


             In order to more quickly be able to directly access localhost / phpmyadmin and write the name of the database that will be created and click Create as shown below :




          The next step is to create the necessary tables, as an example we will create a table of products, transactions, and members

a. Creating a table with writing manuals


Create Table Produk

create table Produk(
KodeProduk char(5) not null constraint PK_Produk primary key ,
NamaProduk varchar(70) not null,
Harga numeric(18,2) not null,
Diskon numeric(18,2) null Default 0)

Create Table Transaksi

create table Transaksi(
NoTran char(12) not null constraint PK_NoTran primary key,
TglTran datetime not null,
KodeMember char(7) not null references Member(KodeMember),
TotalBelanja numeric(18,2) not null)

Create Table Member

create table Member(
KodeMember char(7) not null constraint PK_Member primary key,
NamaMember varchar(50) not null,
Alamat varchar(100),
NoTelp varchar(15),
Tipe char(1) not null constraint Ck_Tipe Check(Tipe In('G','S')))


b. Quickly Create Tables


            

Once the product is made then fill in the table fields :



So on the same step for transaction table and the table member..
                



Monday, October 8, 2012

PHP and Database Connection

  Based on how the presentation of information, a web page can be divided into two kinds of the web that are static and dynamic.

   A static web page and displays only the information that same each visitor visits a website. While the dynamic nature of web databases need to be able to manage the information that is required to be presented and used to interact with web visitors.

  Implementation of various applications can be done using a multi-tier models for one or more layers to cooperate.

Model Tree-tiered system:
a. first tier: web client (ex: web browser)
b. Second tier: web server, PHP scripts, connectivity API, and CGI scripts
c. Third tier: database server (MySQL, Oracle, PostgreSQL)

  In order to access a MYSQL table into the programmer must, perform a first connection that can be connected in the form of scripts PHP.

Example PHP script database connection:
<?php
  $koneksi=mysql_connect("localhost","root","");
  if ($koneksi) {
     }
  else {
     }
  mysql_select_db("databasename") or die(mysql_error()); 
?>