Php and Mysql_1

download Php and Mysql_1

of 25

Transcript of Php and Mysql_1

  • 8/6/2019 Php and Mysql_1

    1/25

  • 8/6/2019 Php and Mysql_1

    2/25

    PHP is a powerful tool for making dynamicand interactive Web pages.PHP is the widely-used, free, and efficientalternative to competitors such as Microsoft'sASP.

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    3/25

    PHP stands for PHP: Hypertext PreprocessorPHP is a server-side scripting language, likeASP

    PHP scripts are executed on the serverPHP supports many databases (MySQL,Informix, Oracle, Sybase, Solid, PostgreSQL,Generic ODBC, etc.)

    PHP is an open source softwarePHP is free to download and use

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    4/25

    PHP files can contain text, HTML tags andscriptsPHP files are returned to the browser as plainHTMLPHP files have a file extension of ".php",".php3", or ".phtml"

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    5/25

    MySQL is a database serverMySQL is ideal for both small and largeapplications

    MySQL supports standard SQLMySQL compiles on a number of platformsMySQL is free to download and use

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    6/25

    PHP combined with MySQL are cross-platform(you can develop in Windows and serve on aUnix platform)

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    7/25

    PHP runs on different platforms (Windows,Linux, Unix, etc.)PHP is compatible with almost all serversused today (Apache, IIS, etc.)PHP is FREE to download from the official PHPresource: www.php.netPHP is easy to learn and runs efficiently on

    the server side

    Ramesh Kumareson - IDM Computer Studies Private Limited

    http://www.php.net/http://www.php.net/
  • 8/6/2019 Php and Mysql_1

    8/25

    To get access to a web server with PHPsupport, you can:Install Apache (or IIS) on your own server,install PHP, and MySQLOr find a web hosting plan with PHP andMySQL support

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    9/25

    If your server supports PHP you don't need todo anything.

    Just create some .php files in your webdirectory, and the server will parse them foryou. Because it is free, most web hosts offerPHP support.

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    10/25

    Here is a link to a good tutorial from PHP.net on howto install PHP5:http://www.php.net/manual/en/install.phpDownload PHPDownload PHP for free here:

    http://www.php.net/downloads.phpDownload MySQL DatabaseDownload MySQL for free here:http://www.mysql.com/downloads/index.htmlDownload Apache Server

    Download Apache for free here:http://httpd.apache.org/download.cgiPHP code is executed on the server, and the plainHTML result is sent to the browser.

    Ramesh Kumareson - IDM Computer Studies Private Limited

    http://www.php.net/manual/en/install.phphttp://www.php.net/manual/en/install.phphttp://www.php.net/downloads.phphttp://www.php.net/downloads.phphttp://www.mysql.com/downloads/index.htmlhttp://www.mysql.com/downloads/index.htmlhttp://httpd.apache.org/download.cgihttp://httpd.apache.org/download.cgihttp://httpd.apache.org/download.cgihttp://www.mysql.com/downloads/index.htmlhttp://www.php.net/downloads.phphttp://www.php.net/manual/en/install.php
  • 8/6/2019 Php and Mysql_1

    11/25

    XAMPP is a very easy to install ApacheDistribution for Linux, Solaris, Windows andMac OS X. The package includes the Apacheweb server, MySQL, PHP, Perl, a FTP serverand phpMyAdmin.

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    12/25

    Go to http://sourceforge.net/project/showfiles.php?group_id=61776and click "XAMPP Windows". If necessary, click the "1.7" link to expandthe appropriate version, and choose to download xampp-win32-1.7.0-installer.exe.The XAMPP Control Panel in WindowsRun the installer. If you want, you can choose to install the Apache andMySQL servers as services, which will make them start automaticallyevery time you start Windows. If you don't choose this option, you willneed to use the XAMPP Control Panel application to start the serversindividually each time you need them. This may be desirable if you don'tintend to use your servers that often.Upon completion of installation, the XAMPP Control Panel will open (if not, click Start All Programs Apache Friends XAMPP XAMPPControl Panel). This tool lets you start and stop the various serversinstalled as part of XAMPP.Start Apache and MySQL by clicking on the "Start" buttons next to eachitem. If prompted by Windows Firewall, click the button labelled"Unblock".Go to http://localhost/ . If you are directed to a page with the XAMPPlogo, your installation was successful. Congratulations!

    Ramesh Kumareson - IDM Computer Studies Private Limited

    http://sourceforge.net/project/showfiles.php?group_id=61776http://localhost/http://localhost/http://sourceforge.net/project/showfiles.php?group_id=61776
  • 8/6/2019 Php and Mysql_1

    13/25

    Note that "localhost" (often resolving to the reserved IP address 127.0.0.1) is aspecial name de fined in t he DNS system as a name that a host uses to referenceitself, using the loopback interface. URLs that refer to "http://localhost/" can onlybe used on the system with XAMPP installed. However, by default, XAMPPconfigures Apache to allow connections from outside your system, so people onyour network, or in some cases users from anywhere in the world, may be able toaccess your Apache-served files using your IP address.You can go to http://localhost/phpmyadmin/ to use the locally-installed copy of phpMyAdmin, a tool useful for manipulating your MySQL databases in a graphicalenvironment.On the Windows version of XAMPP, you can use the command-line interface (CLI)version of PHP at C:\xampp\php\php.exe. On Mac OS X this is located at/Applications/xampp/xamppfiles/bin/php. If you want to be able to execute PHPby simply typing "php" at the command line in either operating system, you needto add the directory containing PHP (C:\xampp\php on Windows and/Applications/xampp/xamppfiles/b in on Mac O S X) t o your "path" variable. Thereare tutorials available for doing this on Windows and on Mac OS X .If you want to fine-tune y our Apache, MySQL, or PHP settings, you can go tohttp://localhost/xampp/ to view and change parts of your XAMPP configuration. If you are feeling especially adventurous, you can also hand-tweak the configurationfiles in the XAMPP installation directory.

    Ramesh Kumareson - IDM Computer Studies Private Limited

    http://en.wikipedia.org/wiki/Loopbackhttp://en.wikipedia.org/wiki/Loopbackhttp://localhost/phpmyadmin/http://www.computerhope.com/issues/ch000549.htmhttp://keito.me/tutorials/macosx_pathhttp://www.computerhope.com/issues/ch000549.htmhttp://keito.me/tutorials/macosx_pathhttp://localhost/xampp/http://localhost/xampp/http://localhost/xampp/http://keito.me/tutorials/macosx_pathhttp://www.computerhope.com/issues/ch000549.htmhttp://localhost/phpmyadmin/http://en.wikipedia.org/wiki/Loopback
  • 8/6/2019 Php and Mysql_1

    14/25

    A PHP scripting block always starts with . A PHP scripting block can beplaced anywhere in the document.On servers with shorthand support enabled youcan start a scripting block with .For maximum compatibility, we recommend thatyou use the standard form (

  • 8/6/2019 Php and Mysql_1

    15/25

    A PHP file normally contains HTML tags, just likean HTML file, and some PHP scripting code.Below, we have an example of a simple PHP scriptwhich sends the text "Hello World" to thebrowser:

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    16/25

    Each code line in PHP must end with asemicolon. The semicolon is a separator andis used to distinguish one set of instructionsfrom another.There are two basic statements to output textwith PHP: echo and print . In the exampleabove we have used the echo statement tooutput the text "Hello World".Note: The file must have a .php extension. If the file has a .html extension, the PHP code

    will not be executed.

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    17/25

    In PHP, we use // to make a single-line comment or /* and*/ to make a large comment block.

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    18/25

    Variables are used for storing a values, like text strings,numbers or arrays.When a variable is declared, it can be used over and overagain in your script.All variables in PHP start with a $ sign symbol.The correct way of declaring a variable in PHP:$var_name = value;New PHP programmers often forget the $ sign at thebeginning of the variable. In that case it will not work.Let's try creating a variable containing a string, and avariable containing a number:

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    19/25

    In PHP, a variable does not need to be declaredbefore adding a value to it.In the example above, you see that you do nothave to tell PHP which data type the variable is.PHP automatically converts the variable to thecorrect data type, depending on its value.In a strongly typed programming language, youhave to declare (define) the type and name of thevariable before using it.In PHP, the variable is declared automaticallywhen you use it.

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    20/25

    A variable name must start with a letter or anunderscore "_"A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )A variable name should not contain spaces. If a variable name is more than one word, it

    should be separated with an underscore($my_string), or with capitalization($myString)

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    21/25

    String variables are used for values that containscharacters.In this chapter we are going to look at the most commonfunctions and operators used to manipulate strings in PHP.After we create a string we can manipulate it. A string canbe used directly in a function or it can be stored in avariable.Below, the PHP script assigns the text "Hello World" to astring variable called $txt:The output of the code above will be:Hello World

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    22/25

    There is only one string operator in PHP.The concatenation operator (.) is used to put two stringvalues together.To concatenate two string variables together, use theconcatenation operator:The output of the code above will be:Hello World! What a nice day!If we look at the code above you see that we used theconcatenation operator two times. This is because we hadto insert a third string (a space character), to separate thetwo strings.

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    23/25

    The strlen() function is used to return the lengthof a string.Let's find the length of a string:The output of the code above will be:12The length of a string is often used in loops orother functions, when it is important to knowwhen the string ends. (i.e. in a loop, we wouldwant to stop the loop after the last character inthe string).

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    24/25

    The strpos() function is used to search for character withina string.If a match is found, this function will return the position of the first match. If no match is found, it will return FALSE.Let's see if we can find the string "world" in our string:The output of the code above will be:6The position of the string "world" in our string is position

    6. The reason that it is 6 (and not 7), is that the firstposition in the string is 0, and not 1.

    Ramesh Kumareson - IDM Computer Studies Private Limited

  • 8/6/2019 Php and Mysql_1

    25/25

    Next Week PHP Operators

    Ramesh Kumareson IDM Computer Studies Private Limited