Sunday, April 26, 2009

Effective interaction between php and MySQL

As i know how to make HTML forms,and have moderate knowledge of PHP and MySQL so its time to try out some data sharing between php and MySQL.


  • Establishing a connection
    First of all we have to build a connection between php functions and MySQl and the command to do that is:-
    mysql_connect("Hostname","username","password");

  • Selecting a database
    Once the connection is established an appropriate database is selected and the command for that is:-

    mysql_select_db("database_name",connection_variable);

  • Executing the mysql queries
    mysql_queries is executed by the following command:-

    mysql_query( mysql_query variable, connection variable);



( Meloni , Julie C. 2005," Sams teach yourself PHP,MysQL and Apache all in one", Sams , ed:2.)

Friday, April 24, 2009

Exploring MySQL

Before jumping on to project, i decided to do some data manipulation in MySQL so that i have better understanding of it syntax. This turn out to be good decision as i have work on any Database software for about 6 month, after a long hit and trial i learn to following things about MySQL database:-


  • MySQL Data Types

    • Numeric data types

      • INT
      • TINYINT
      • SMALLINT
      • MEDIUMINT
      • BIGINT
      • FLOAT(M,D)
      • DOUBLE(M,D)
      • DECIMAL(M,D)

        Note: term signed and unsigned can be used in numeric data types

    • Date and Time types

      • DATE
      • DATETIME
      • TIMESTAMP
      • TIME
      • YEAR(M)

    • String Types

      • CHAR(M)
      • VARCHAR (M)
      • BLOB or TEXT
      • TINYBLOB or TINYTEXT
      • MEDIUMBLOB or MEDIUMTEXT
      • LONGBLOB or LONGTEXT
      • ENUM



  • First thing is to create our database which can be done by executing following command:-
    CREATE DATABASE [IF NOT EXISTS] "database name"
    [[default] CHARACTER SET "character set name"]
    [[default] COLLATE "collation name"]

    (Sheldon, Robert and Moes Geoff 2005,"Beginning MySQL",JohnWiley and sons,pg 140).

    or simply:-

    CREATE DATABASE "database name";
    if CHARACTER SET AND COLLATE are not define that MySQL will use the default value.

  • use this command is used to change database.The syntax of this is:-
    mysql> use datbase_name
    .
    Note: this command does not followed by semi colon(;) like other commands


  • For creating table the command is:-
    mysql>CREATE TABLE table_name (column name column type);

    Note: table would be created in the selected database,make sure the right database is selected.
  • For entering data in to table the command is:-

    mysql>INSERT INTO table_name (column list) VALUES (column values);

  • SELECT command is used to retrieve data from the tables.

    mysql>SELECT expressions_and_columns FROM table_name
    [WHERE some_condition_is_true]
    [ORDER BY some_column [ASC | DESC]
    [LIMIT offset, rows]


    ORDERBY by column_name can be used with select to display result in specified sorted order.

  • Selecting from a Multiple Tables can be done with the following command:-
    mysql> (select column list) from (table name) where condition;

  • For UPDATING the records is done by:-

    • mysql> update table_name set Column_name = Value;

    • For conditional Updates the syntax is:-

      mysql> update Table_name set column_name where condition;


  • Replacing a RECORD can be done by:-

    mysql> replace into table_name values ();

  • Deleting a record :-
    mysql> DELETE from table_name [where some_condition_is_true][Limit rows]( Meloni , Julie C. 2005," Sams teach yourself PHP,MysQL and Apache all in one", Sams , ed:2.)

  • Length and concatenation function

    • length(), octet_length().char_length(), and character_length() all calculate number of characters in string. syntax is:-

      mysql> select length ('string';


    • To concatenate two string, MySQL have concat() function,
      To concatenate a string with space the function is concat_ws();

    • Trimming and padding
      rtrim() and ltrim() remove the white spaces from the right and left of the string respectively. rpad() and lpad() adds a string to the right and left of the string respectively.

    • To locate a part of string in another string the MySQL has Locate(), syntax is:-

      mysql> select locate( 'string to be find', ' from this string', position from where to start searching);


    • To extract a substring from a target string, mysql has:-
      Substring(), Left() and Right() functions:-


      mysql> select substring("target string", starting position, end position);

      mysql> select left("target string", till this position from left);

      mysql> select right("target string", till this position from right);

    • String modification functions
      For transforming a string into lower and upper case lcase() and ucase() are available:-
      mysql> select lcase('string' or condition)

      mysql> select ucase('string' or condition)

      MySQL have repeat() for repeating a string number of time and replace() from replacing a occurrence of given string from target string.

      mysql> select repeat(" string", number of time);

      mysql> select replace ( ' given string', ' string to be replace',' string with which to replace');









( Meloni , Julie C. 2005," Sams teach yourself PHP,MysQL and Apache all in one", Sams , ed:2.)
(Sheldon, Robert and Moes Geoff 2005,"Beginning MySQL",JohnWiley and sons).

Wednesday, April 22, 2009

How to set Root password for "WAMP"

Hello! Guys,
After installing 'WAMP' last night i face series of problems and today i want to share with you all what you should do if you face the similar problem.

  • Installation of WAMP was successful, but still web browser could not execute php code?

After installing "WAMP" i thought its nice idea to try some php code at home, rather than uploading every php file on uni server and test it. I created a folder inside www folder in C:\Wamp and put my php file in it,as written on www.wampserver.com to my surprise whenever i try to view this page in web browser, the browser did't seem to execute php code but it was showing text written with in HTML elements properly.

The reason for this behavior was my firewall block the php server, so if you guys have firewall installed on you system make your you permit php server. Don't forgot to put WAMP server online , you can do this by left clicking on wamp icon in status bar and selecting option "put online" .


  • Unable to open MySQL console?

Now, i am able to figure out how to execute php code but the problem now is whenever i try to open MySQL console it ask for an password, which i don't have.
so, now i have to set the root password but how to do that?.....
After looking around INTERNET for this. finally i found the answer which involve following steps:-

  • open the phpMyAdmin, you can do this by left clicking on wamp server icon in status bar.
  • click on the privileges tab.
  • Then look for User "root" with host "local host" click on edit privileges( which is on right end of this row).
  • scroll down to change password column and type in password twice and click go.
  • open c:\WAMP\APPS\phpmyadmin3.1.1\config.inc.php in the text editor and search for $cfg['Servers'][$i]['auth_type'] = 'config'; and replace 'config' with 'cookie'.
  • Now look for $cfg['Servers'][$i]['password'] = 'your_password'; and type in your password in between single quotes.
  • its all done...now save this file. exit WAMP server and restart it you would be able to use MySQL console now....


cheers.....

Tuesday, April 21, 2009

Difference between "GET" and "POST"

Technical difference according to HTML specification is, when "GET" is used the form data is encoded(by browser) in to URL whereas in "POST" the data is to appear with in the message body.According to the usage recommendation giving in the specification the "GET" should be used the when the form processing is "idempotent", which mean "GET" is used for the purpose of data retrieving whereas "POST" may be used when service associated with the processing of a form has a side effects like storing or updating data, sending email or ordering products.

Difference in server side processing

As the data is encoded in different way depending on whether it is send by GET or POST, different decoding algorithm is needed which may require some changes in the script that processes the form submission. For example, when using the CGI interface if the method is "GET" the data is received in environmental variable, whereas it is received in standard input when the method is "POST".

Some exceptions were "POST" can be used for idempotent queries

  • Method "GET" is inapplicable if the data present on form is non-Ascii, so using the POST in this case is less dangerous.

  • Method "GET" can not handle long URL so if the from data set is large comprises of hundreds of character, using the POST is advisable.

  • Method "POST" can be used in order to make it less visible to user how the the form queries but its not very effective as it just prevent user from seen the form data in the URL from the user, however user can see the source code of form element.

Saturday, April 18, 2009

History of World Wide Web ( A Report)

In 1980 Tim Berner-lee, while working at CERN(Centre European pour la Recherche Nucleaire -or- European Laboratory for Particle Physics) he acknowledged difficulty to access data simultaneously as the data was stored in different databases on different machines with practically no interaction or connectivity.
He wished to develop a system that would let him quickly and automatically retrieve a mailing address for the receiver of a letter that the might be composing. And he develop a program “Enquire –Within-Upon-Everything” known as Enquire for short, he left CERN soon after the completion of the “Enquire”.

In 1989, He returned back to CERN and witnesses a change in “computing culture” there which revolved around distributed computing and object-oriented programming. Introduction of object oriented technologies by NeXT had made rapid system development and prototyping in a UNIX environment feasible.

In March 1989, He submitted an “ Information Management: A Proposal” highlighting the development of hypertext system that provide a single user-interface to stored information such as reports, notes, data-bases, Computer documentation and online systems help. The proposal’s main objectives were:

• The provision of a simple protocol for requesting human readable information stored in remote systems accessible using networks.
• to provide a protocol by which information could automatically be exchanged in a format common to the information supplier and the information consumer
• the provision of some method of reading text (and possibly graphics) using a large proportion of the display technology in use at CERN at that time
• The provision and maintenance of collections of documents, into which users could place documents of their own.
• To allow documents or collections of documents managed by individuals to be linked by hyperlinks to other documents or collections of documents.
• the provision of a search option, to allow information to be automatically searched for by keywords, in addition to being navigated to by the following of hyperlinks
• To use public domain software wherever possible and to interface to existing proprietary systems.
• To provide the necessary software free of charge.

In 1990, Robert cailliau help Tim to reformulate his proposal and World Wide Web was born as a side effect of the research in particle physics.

reference:
http://ei.cs.vt.edu/~wwwbtb/book/chap1/web_hist.html( link at UTS online Week3:Subject doucment)