Skip to main content

Posts

MYSQL CONNECTION USING PDO WITH PHP

Hello guys, In the previous tutorial we have seen how to connect to MySQL database with PHP using MySQLi. Today we will learn how to connect with PDO. As a PHP programmer we have learned how to access database by using either MySQL and MySQLi. As of PHP 5.1, there's a better way. PHP Data Objects(PDO) provide methods for prepared statements and working with objects that will make you far more productive! PDO Introduction :        PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. Database Support:       The extension can support any database that a PDO driver has been written for. The following drivers currently implement the PDO interface: PDO_CUBRID Cubrid PDO_DBLIB FreeTDS / Microsoft SQL Server / Sybase PDO_FIREBIRD Firebird PDO_I...

MYSQL DATABASE CONNECTION WITH PHP

Hello friends, today we will learn how to connect to  MySQL  database with PHP. This tutorial will require a MySQL database and a web development environment using mysql, apache and php and a simple text editor. The tutorial takes you through establishing a  MySQL  connection using php on a web page, connecting to a  MySQL  table and retrieving the results and displaying them back on the web page. Earlier versions of PHP used the  MySQL  extension.However, this extension was depreciated in 2012. Later can work with  MySQL  database using MySQLi extension (the "i" stands for improved) PDO (PHP Data Objects)        The main difference between these two are if you want to switch your project to another database PDO makes it easy(since it can connect 12 different databases). You only have to change the connection string and a few queries. With MySQLi, you will need to rewrite the entire code - queries included.In this t...

PHP FROM COMMAND LINE

Hello guys, today we will learn how to write PHP programs through command line. Generally, PHP is use for web applications but  there are occasions where we can use command line such as automatic mail sending, log tracking, cron jobs etc. PHP supports CLI SAPI(Command Line Interface Server API) for executing the script from command line. This SAPI will differ from other interfaces based on the IO practices, configuration defaults, buffering and more. For example, IO practices – it will not support PHP request method (GET, POST). Instead, it uses IO streams. Command line execution time –  In the command line, the execution time limit is unlimited by default. Buffering – implicit_flush is enabled to display output. It also supports output buffering. Some of the PHP CLI SAPI commands: Command Description -i To display command line PHP info. -v To show version details. -r To execute PHP script without delimiters -f To execute PHP file. -l To check the syntax of the...

SET, GET AND UNSET SESSION VARIABLES IN PHP

Session is a way to store information across multiple pages in a website. How to start a session: A session can be started  by using session_start() function.We can set session variable by using PHP global variable $_SESSION. consider an example: create a new page demo1.php and start a new PHP session in this page and set some session variables. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <?php // Start the session session_start (); ?> <!DOCTYPE html> <html> <body> <?php // Set session variables $_SESSION [ "username" ] = "sowmya" ; $_SESSION [ "email" ] = "sowmya.vejerla@gmail.com" ; echo 'username : ' . $_SESSION [ 'username' ]; echo '<br>' ; echo 'email : ' . $_SESSION [ 'email' ]; ?> </body> </html> Next we create another page demo2.php ,from this page we will access  the session variables that we set ...

PHP AND HTML IN ONE PAGE

There are two ways you can use HTML in your PHP page. The first way is  by placing HTML outside the PHP tags.You can put it in the middle if you can open and close PHP tags. Here is an example for it: 1 2 3 4 5 6 7 8 <html> <title>PHP INSIDE HTML</title> <body> <h1>Example</h1> <?php echo "hello world" ?> </body> </html> As you can see you can use any HTML tags without need any extra work,except saving as .php file. The second way is by using PRINT and ECHO statements. Here is an example for it: 1 2 3 4 5 6 7 8 9 <?php Echo "<html>" ; Echo "<title>HTML with PHP</title>" ; Echo "<b>My Example</b>" ; //your php code here Print "<i>Print works too!</i>" ; ?> This is simplest and quick method if you only have a line or so to do.Using both these methods you can embed HTML and PHP in same page to gave them a nice forma...

PHP AND ITS BENEFITS FOR DEVELOPERS

What is PHP and what can it do for our website ? Generally PHP is used to add functionality to our website that HTML alone can't do.However PHP is much more than that! What is PHP? PHP is server-side scripting language.This may seems confusing but it is very clear and straight-forward. What is Server-side scripting language? This means that everything PHP does occurs in server side.As an example, if a user is updating a profile on a networking site, the server-side scripts will gather the information the user enters, the application will process it on the server, then interact with the database to update that information there.And, because PHP is executed on the server, the client cannot view the PHP code. What can PHP do? PHP does anything a PHP programmer wants it to, but it's  main goal is to allow web developers to write dynamically generated pages quickly.  Common uses of PHP include: Perform calculations and mathematical equations Access a wide range of databas...