Posts

Showing posts from 2020

PHP array

Image
  An array stores multiple values in one single variable. In PHP, the array() function is used to create an array. Example: <?php $pets = array ( "dog" , "cat" , "rabbit" ); echo $pets [ 0 ] . "," . $pets [ 1 ] . "," . $pets [ 2 ]; ?> Output: dog,cat,rabbit An array is a special variable, which can hold more than one value at a time. If you have a list of student names, storing the names in single variables could like this, $name1 = "Peter" $name2 = "Mickle" $name2 = "Bravo" However, what if you want to loop through the names and find a specific one? And what if you had 3 names, but 1000? The solution is to create an array . An array can hold many values under a single name, and you can access the values by referring to an index number. There are three different kind of arrays. Numeric array – Arrays with a numeric index Associative array – Arrays with named keys

PHP code for Oracle Database Connection

Image
If you want to write a PHP script for Oracle database connection, before you need to enable the extension in your php.ini file. ;extension=php_oci8.dll ;extension=php_oci8_11.g.dll You also need oracle client install to your computer and create a SID from Oracle Net Manager. Oracle Client Download PHP provides OCILogon() function to open a oracle database connection. Syntax: <?php $db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = localhost)(PORT = 1521)))(CONNECT_DATA=(SID=orcl)))" ; $c = OCILogon( "username" , "password" , $db ); if ( $c ) { echo "Successfully connected to Oracle.\n" ; OCILogoff( $c ); } else { $err = OCIError(); echo "Connection failed" . $err [ text ]; } ?> Host=hostname SID=database name

PHP Script for MySqli Database Connection

Image
PHP provides mysqli_connect() function to open a database connection. Syntax: mysqli_connect("hostname", "username", "password", "database_name"); The hostname parameter in the above syntax specify the host name (e.g. localhost) or IP address of the MySQL server, whereas the username and password parameters specifies the credentials to access MySQL server, and the database parameter, if provided will specify the default MySQL database to be used when performing queries. Example: <html>    <head>       <title> MySQLi Database Connection </title>    </head>     <body>       <?php          $hostname = "localhost" ;           $username = "root" ;           $password = "" ;           $conn = mysqli_connect ( $hostname , $username , $password ,  $password );             if ( ! $conn ){             die ( 'Could not connect: ' . mysqli_error() );