Friday, January 13

PHP Connect to My SQL Database

<?php
$ng_username = "your_user_name";//localhost
$ng_password = "your_user_password";//password
$ng_hostname = "localhost/servername"; //127.0.0.1

//The connection to the database using PHP
$dbhandle = mysql_connect($ng_hostname, $ng_username, $ng_password)
  //or die(mysql_error());//Show Error generated.
  or die("in database connection details : Does not connect Mysql Databased ");
echo "database connection details : Your Database Connected to MySQL succesfully<br>";
?>


//Other way to select a database to work with


<?php
$selected = mysql_select_db("DatabaseName",$dbhandle_varname)or die("details of connect database - can not connect your database");
?>

Second way to external php to MYSQL connect databased- config.php
----------

<?php
$username_ng = "root";//localhost
$password_ng = "ng4free";//password
$hostname_ng = "localhost or ip"; //127.0.0.1

//connection to the database
$dbhandle = mysql_connect($hostname_ng, $username_ng, $password_ng)
  or die("Disconnect your databased in MYSQL/ Unable to connect to MySQL : details");
echo "You are Connected to MySQL Databased<br>";

$selected_databased = mysql_select_db("users",$dbhandle)or die("Databased Details : does not/Could not select users");

?>

Full Example : How to connect to MySQL database using PHP

<?php
$user_username = "Default (root)Your username or root";
$user_password = "Host (Password)genrated password";
$user_hostname = "localhost / server host";

//The above us to connection to the database
$dbhandle = mysql_connect($user_hostname, $user_username, $user_password)
 or die("Error : Unable to connect to MySQL");
echo "PHP to connect MySQL Databased success. <br>";

//The Script is select a database to work with
$selected = mysql_select_db("test",$dbhandle)
  or die("Could not select test");

//IT's is query execute the SQL query(handle) and return records
$result_data = mysql_query("SELECT your_id, modelname,year FROM cars_company");

//Loop through fetch tha data from the database Using PHP Script
while ($row = mysql_fetch_array($result_data)) {
   echo "ID:".$row{'your_id'}." Name:".$row{'modelname'}."Year: ". //Print display the results
   $row{'year'}."<br>";
}
//Dtabased close the connection
mysql_close($dbhandle);//connection close
?>

Now Go To Localhost/phpmyadmin and to create 'cars_company' database on your MySQL server you should run the following script:

CREATE DATABASE `users`;
USE `cars_company`;
CREATE TABLE `cars_company` (
   `your_id` int UNIQUE NOT NULL,
   `modelname` varchar(40),
   `year` varchar(50),
   PRIMARY KEY(your_id)
);

INSERT INTO cars_company VALUES(1,'ngcomapny','2000');
INSERT INTO cars_company VALUES(2,'ng4free','2004');
INSERT INTO cars_company VALUES(3,'ngdemo','2001');

Wednesday, January 11

Visual Studio 2013 Tips and Tricks

You can use below tips and trick in visual studio to enhance the speed of coding and development.
(1) Matching brace/comment/region/quote
“Ctrl+]” can be used to the match brace, region, quote. It can also be used to the match comment, region or quote depending on where is the cursor now.
(2) Create Property By Shortcut
Creating Properties are very common to get and/or set values. For writing Property, you do not need to write it completely. just type PROP and then press TAB key twice.
(3) Vertical block selection.
Select Alt key and then select the area you want with your mouse.

(4) Auto Complete
Using IntelliSense in Visual Studio you can complete method, variable, class, object, property etc. by just writing its initial. Use Ctrl + Space or Alt + Right Arrow.
(5) Bookmark
Using Bookmark you can navigate to code in visual studio.
Create/Remove Bookmark – Ctrl+K, Ctrl+K
Move to next bookmark – Ctrl+K, Ctrl+N
Move to previous bookmark – Ctrl+K, Ctrl+P
Clear all bookmarks – Ctrl+K, Ctrl+L

(6) Build and Debug

Build – Ctrl+Shift+B
Run – Ctrl+F5
Debug – F5
Cycle through build errors – F8

(7) Move Code Up or Down
If you want to move a line up then just keep the cursor on that line and press “Alt + Up Arrow key” similar to this if you want to move the line down then just keep the cursor on that line and press “Alt + Down Arrow key”.

(8) Comment Code block
Comments are used for documentation purpose or temporarily disable the code. You can comment block of code by selecting that portion and then press Ctrl-K + C. To uncomment code select code block and press Ctrl-K + U.

(9) Switch between Currently open tabs.
You can open lastly visited tab in visual studio by pressing Ctrl + Tab and for opposite direction Ctrl + Shift + Tab
So, these are some commonly used shortcuts which will save your time.

OOPS Concepts, Features & Explanation with Example in C#.Net

– OOPS = Object Oriented Programming.
– OOPS is a programming technique which provides an efficient way to manage Object and its behaviour across a system.
– OOPS provides a way to show/hide relevant data.
– OOPS provides an efficient way for code reusability.

Here I will explain you important concepts of OOPs.

(1) Class

– The class can be considered as a blueprint for an object.
– A class is a collection of object.
– It is compulsory to create a class for representation of data.
– Class do not occupy memory space, so it is a merely logical representation of data.

The syntax for declaring a class.

public class College
{
//your code goes here.
}

(2) Object

– The object is variable of type Class.
– Object possess property and behaviour.
– As a class do not occupy any memory, so to work with real-time data representation you need to make an object of the class.

Syntax
– Here is the syntax to create an object(we just created above).

College objCollege = new College();

(3) Encapsulation

– Encapsulation is the process of keeping item into one logical unit.
– Encapsulation is a technique used to protect the information in an object from another object.
– The concept of data hiding or information hiding can be achieved by encapsulation.
– In c#,Encapsulation is implemented using the access modifier keywords. C# provides 5 types of access modifier,
which are listed below.
(i) Public : Public members are accessible by any other code in the same  assembly or another assembly that reference it.
(ii)Private : Private member can only be accessed by code in the same class.
(iii)Protected: Protected member can only be accessed by code in the same class or in a derived class.
(iv)Internal : Internal member can be accessed by any code in the same assembly, but not from another assembly.
(v) Protected Internal : Protected Internal member can be accessed by any code in the same assembly, or by any derived class in another assembly.

(4) Polymorphism

– Polymorphism is an ability to take more than one form in different case/scenario.
– It can make different logical units but with the same name. Its behaviour is executed based on input or the way it is called.

class PolymorphismExample
{
public void Add(int p_Value1, int p_Value2)
{
Console.WriteLine(“Result ={0}”, p_Value1 + p_Value2); // This will perform addition of p_Value1 and p_Value2
}

public void Add(string p_Value1, string p_Value2)
{
Console.WriteLine(“Result ={0}”, p_Value1 + p_Value2); // This will perform concatenation of p_Value1 and p_Value2
}
}

(5) Inheritance

– Inheritance provides a way to inherit member of another class.
– It Provides a way to reuse code which is already written.

class InheritanceExample
{
public abstract class AllCar
{
public abstract string GetCarName();
}

public class HondaSeries : AllCar
{
//this method name matches with same signature/parameters in AllCar class
public override string GetCarName()
{
return “Car Name is Honda City”;
}
}

public static void Main(string[] args)
{
AllCar objAllCar = new HondaSeries();
Console.WriteLine(objAllCar.GetCarName());
Console.Read();
}
}

Wednesday, January 4

How to convert an array to object in PHP?

How to convert an array to object in PHP?
This post will show you how to convert convert an array to object with different conditions of array in PHP.
Convert array to object using json.


The Best, quick, dirty, very effective and easy way (also my personal recommendations) to convert array to objects using json_encode and json_decode, it will turn the entire array (also including sub elements of array) into an object.

// Convert array into an object
$object = json_decode(json_encode($array));

var_dump ($object); // print object value with var_dump   


Convert associative array in to object

$array = Array ( 'keys' => "status value" );
// convert array in to object
$object = (object) $array;

var_dump ($object); // print object value with var_dump

var_dump($object->keys); // echo object value using key

Convert mulch-dimensional array( with same associative array) to object with simple way


$array = array (
    "0" => Array( "status_key" => "test value of keys 0" ),
    "1" => Array( "status_key" => "test value of keys 1" ),
    "2" => Array( "status_key" => "test value of keys 2" )
);

simple way convert array in to object

// convert array in to object
$object = (object) $array;
var_dump ($object); // print object value with var_dump

This is another way to convert array to object with foreach loop

$object = new stdClass();

foreach ($array as $keys => $value ) {
    $object->{$keys} = $value;
}
var_dump ($object); // print object value with var_dump

In this mulch-dimensional array we will convert into an object.

$array = array (
    "test array",
    array( "keys test 1 value" ,"keys test 2 value" ,"keys test 3 value" ),
    array( "keys test 1 value" ,"keys test 2 value" ,"keys test 3 value" ),
    array( "keys test 1 value" ,"keys test 2 value" ,"keys test 3 value" ),
    array( "keys test 1 value" ,"keys test 2 value" ,"keys test 3 value" ),
);

$object = new ArrayObject($array);
var_dump ($object); // print object value with var_dump

foreach ($object as $keys => $val){
    if (is_array( $val )) {
        foreach($val as $sub_key => $sub_val) {
           echo $sub_key . ' => ' . $sub_val."<br>";
        }
    }
    else
    {
           echo $val."<br>";
    }
}

Convert array to object using function (with same associative array)

function arrat_to_object($array) {
    $objects = new stdClass();
    foreach ($array as $keys => $value) {
        if (is_array($value)) {
            $value = arrat_to_object($value);
        }
        $objects->$keys = $value;
    }
    return $objects;
}


$object = arrat_to_object($array); // pass array
var_dump ($object); // print object value with var_dump

Convert Manually array in to an object

$object = object; // assign array
foreach ($array as $keys => $values) {
    $object->{$keys} = $values;
}
var_dump ($object); // print object value with var_dump 


 

login customer programmatically – Magento

Magento – How to login customer programmatically

This post show login customer programmatically in Magento. In this given code will allow to login user/customer to login if they are not logion already. If user is not login then this code create session and allow and set seesion and allow login in magento website to user programmatically.

Y2meta free Download Youtube videos in MP3, MP4, WEBM, M4A formats - 2022 - https://infinityknow.com/y2meta/

Top 10 Profile BackLink is bellow...... 



function user_login( $user_email , $user_password ) {
    umask(0);
    ob_start();
    session_start();
    Mage::app('default');
    Mage::getSingleton("core/session", array("name" => "frontend")); // get Singleton of session
    $website_Id   = Mage::app()->getWebsite()->getId(); // get id of store or website
    $store_detail = Mage::app()->getStore();
    $uses_detail = Mage::getModel("customer/customer");
    $uses_detail->website_id = $website_Id;
    $uses_detail->setStore( $store_detail );
    try
    {
        $uses_detail->loadByEmail( $user_email );
        $session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($uses_detail);
        $session->login( $user_email , $user_password );
    }
    catch(Exception $exception)
    {
        echo $exception->getMessage(); // print Exception Message
    }
}

// check user is login or not
if(!Mage::getSingleton('customer/session')->isLoggedIn())
{
    $user_email = "example@mail.com"; // user email id
    $user_password = "add magento login password";
    user_login( $user_email , $user_password );   
}
else
{
    echo "user is already login";
}

customer details – Get logged in customer details – Magento

Magento – How to Get Logged In customer details – Full Name, First Name, Last Name and Email Address

This post is use for get detail of Logged In customer details in Magento. In this post we check Customer is login or not, if Customer is login then we call function get_customer_detail(), It will tack all detail of Logged In Customer.

// function to get user detail
function get_customer_detail()
{
    // get current user detail
    $_customer = Mage::getSingleton('customer/session')->get_customer();
    // remove comments for show all detail of Customer
    // echo "</pre>
    // print_r($_customer);
    // echo "</pre>";
    // basic detail of customer
    echo $_customer->getPrefix();
    echo $_customer->getName(); // Full Name
    echo $_customer->getFirstname(); // First Name
    echo $_customer->getMiddlename(); // Middle Name
    echo $_customer->getLastname(); // Last Name
    echo $_customer->getSuffix();
    // other customer details
    echo $_customer->getWebsiteId(); // get ID of website/store
    echo $_customer->getEntityId(); // get Entity Id
    echo $_customer->getEntityTypeId(); // get Entity Type Id
    echo $_customer->getAttributeSetId(); // get Attribute Set Id
    echo $_customer->getEmail(); // get customer email Id
    echo $_customer->getGroupId(); // get customer Group Id
    echo $_customer->getStoreId(); // get customer Store Id
    echo $_customer->getCreatedAt(); // get Created date(yyyy-mm-dd hh:mm:ss)
    echo $_customer->getUpdatedAt(); // get getUpdated date(yyyy-mm-dd hh:mm:ss)
    echo $_customer->getIsActive(); // customer is active 1 or 0(not active)
    echo $_customer->getDisableAutoGroupChange();
    echo $_customer->getTaxvat();
    echo $_customer->getPasswordHash();
    echo $_customer->getCreatedIn(); // get Created In
    echo $_customer->getGender(); // get customer Gender
    echo $_customer->getDefaultBilling(); // get Default Billing
    echo $_customer->getDefaultShipping(); // get Default Shipping
    echo $_customer->getDob(); // get customer Dob (yyyy-mm-dd hh:mm:ss)
    echo $_customer->getTaxClassId(); // get TaxClass Id
}

// check user is login or not
if(!Mage::getSingleton('customer/session')->isLoggedIn())
{
get_customer_detail();
}
else
{
echo "user is already login";
}

 

MySQL Select Query in php to select the records

MySQL Select Query is used to select the records from MySQL database tables in php

how to use MySQL Select Query is used to select the records from MySQL database tables using php.

PHP Select Data From MySQL(MySQL Select Query)

  PHP Select Data From MySQL

database name :: onlinecode_db
table name :: user_table
+----+------------+-----------+-----------------------------+
| id | first_name | last_name | user_email                  | // column name
+-----------+------------+-----------+----------------------+
| 1  | Peter      | Kong      | peterKong@mail.com          |
| 2  | John       | smith     | johnsmith@mail.com          |
| 3  | Shuvo      | Kent      | Shuvokent@mail.com          |
| 4  | John       | Habib     | johnHabib@mail.com          |
| 5  | Anthony    | Potter    | Anthonypott@mail.com        |
+-----------+------------+-----------+----------------------+

$database_host = 'localhost'; // database host name
 // if using port then add port $database_host = 'localhost:3036'; 
 $database_user = 'database_user'; // database user name
 $database_pass = 'database_password'; // database user password
 $database_name = 'onlinecode_db';  // database name
 
// connect with database
 $database_conn = mysql_connect($database_host, $database_user, $database_pass);
 
 // check database connection
 if(! $database_conn )
 {
     // error in database connection
     die('Could not connect to database : ' . mysql_error());
 }
 $sql_select_query = 'SELECT id,first_name,last_name,user_email FROM user_table';

 mysql_select_db($database_name);
 $sql_result = mysql_query( $sql_select_query, $database_conn );
 if(! $sql_result )
 {
     // error in sql query or Fetch data
     die('Could not get data: ' . mysql_error());
 }
 while($result = mysql_fetch_array($sql_result, MYSQL_ASSOC))
 {
     echo "User ID :{$result['id']}".
          "First Name : {$result['first_name']}".
          "Last Name : {$result['last_name']}".
          "Email Address : {$result['user_email']}";
 }
 echo "Get data successfully";
 
 // close connection with Mysql database
 mysql_close($database_conn);   


PHP Select Data From MySQLi Object-Oriented(MySQL Select Query)

 $database_host = 'localhost'; // database host name
// if using port then add port $database_host = 'localhost:3036'; 
$database_user = 'database_user'; // database user name
$database_pass = 'database_password'; // database user password
$database_name = 'onlinecode_db';  // database name

// connect with database
$database_conn = new mysqli($database_host, $database_user, $database_pass, $database_name);

// check database connection
if ($database_conn-&gt;connect_error)
{  
    // error in database connection
    die("Could not connect to database : " . $database_conn-&gt;connect_error);
}

$sql_select_query = 'SELECT id,first_name,last_name,user_email FROM user_table';
$sql_result =  $database_conn-&gt;query($sql_select_query);

if ($sql_result-&gt;num_rows &gt; 0) {
    // output data of each row
    while($result = $sql_result-&gt;fetch_assoc()) {
        echo "User ID :{$result['id']}".
         "First Name : {$result['first_name']}".
         "Last Name : {$result['last_name']}".
         "Email Address : {$result['user_email']}";        
    }
} else {
    echo "No data found";
}

// close connection with MySQLi database
$database_conn-&gt;close();

PHP Select Data From MySQLi Procedural(MySQL Select Query)

  $database_host = 'localhost'; // database host name
    // if using port then add port $database_host = 'localhost:3036'; 
    $database_user = 'database_user'; // database user name
    $database_pass = 'database_password'; // database user password
$database_name = 'onlinecode_db';  // database name

// connect with database
$database_conn = mysqli_connect($database_host, $database_user, $database_pass, $database_name);

// check database connection
if (!$database_conn)
{
    // error in database connection
    die("Could not connect to database : " . mysqli_connect_error());
}
    
$sql_select_query = 'SELECT id,first_name,last_name,user_email FROM user_table';   
$sql_result = mysqli_query($database_conn, $sql_select_query);

if (mysqli_num_rows($sql_result) &gt; 0)
{
    // output data of each row
    while($result = mysqli_fetch_assoc($sql_result)) {
        echo "User ID :{$result['id']}".
         "First Name : {$result['first_name']}".
         "Last Name : {$result['last_name']}".
         "Email Address : {$result['user_email']}";
    }
}
else
{
    echo "No data found";
}

// close connection with MySQLi Procedural
mysqli_close($database_conn);

PHP Select Data From PDO with Prepared Statements(MySQL Select Query)

 
 $database_host = 'localhost'; // database host name  
    $database_user = 'database_user'; // database user name
    $database_pass = 'database_password'; // database user password
$database_name = 'onlinecode_db'; // database name

try
{
    $database_conn = new PDO("mysql:host=$database_host;dbname=$database_name", $database_user, $database_pass);
    // if using port then use port id in PDO
    //$database_conn = new PDO('mysql:host=$database_host;port=5432;dbname=$database_name', $database_user, $database_pass);
   
    // exception for PDO connection error
    $database_conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   
    $sql_select_query = 'SELECT id,first_name,last_name,user_email FROM user_table';

    $database_conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $database_conn-&gt;prepare($sql_select_query);
    $stmt-&gt;execute(); // execute stmt

    // set the resulting(stmt result) array to associative
    $result = $stmt-&gt;setFetchMode(PDO::FETCH_ASSOC);
    foreach(new TableRows(new RecursiveArrayIterator($stmt-&gt;fetchAll())) as $key=&gt;$values)
    {
        echo $key." = ".$values;
    }
}
catch(PDOException $exception)
{
    // error in database connection
    echo "Could not connect to database : " . $exception-&gt;getMessage(); // exception
}

// close connection with PDO
$database_conn = null;


10 Best Chatting Apps In India

  The modern world is all about Internet. There was a time when people use to pay high telephone bills to stay in touch with their friends a...