Tag Archives: PHP

Magento – How to Check if the SKU is Exist?

Hello Friends today I will share with you In Magento – How to Check if the SKU is Exist?

$sku = 'Your Product Sku';
$id = Mage::getModel('catalog/product')->getIdBySku($sku);
if ($id){
    echo "SKU {$sku} exists";
}
else{
    echo "SKU {$sku} does not exist";
}

Where this code will useful.

  • When you import magento products via code then this code is very useful.
  • If you want to load product via sku then this is very useful.
  • if you want to update any particular product  via code then also this is useful.
Advertisements
PDO-Database-connections-and-abstraction

How to enable mod_rewrite for Apache?

For enable mod_rewrite for Apache.

If you are using Ubantu OS and you have apache web server

Step 1 : open your terminal using ctrl + alt +t.

Step 2 : Then wirte

sudo a2enmod rewrite

Step 3 :

sudo service apache2 restart

Step 4: Then, if you’d like, you can use the following .htaccess file.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

If you are using Windows os and you have WAMP or XAMPP

Wamp and XAMPP doesn’t come with default rewrite rule enabled, For enabling the rewrite rules in both of them you need to make changes in httpd.conf so that apache can work with rewrite rules.

For enabling the rewrite rules follow these rules:-

Step 1 : find httpd.conf (usually this file can be found in folder callled conf , config or something along those lines)

Step 2: Find and uncomment the line LoadModule rewrite_module .

Step 3:Find the line with DocumentRoot “C:/path/to/my/root”, There you will find contents like

<Directory>
Options All
AllowOverride All
</Directory>

Step 4: All done now restart the Apache server and you will be all good to go.

How to connect to the ORACLE using PDO?

Today I explain you how to connect with the ORACLE database using PDO.

In PDO(PHP Data Object) it’s very easy to connect with ORACLE.  As per below example you can easily  understand.

<?php
	$user='root'; // Enter your DB User Name.
	$pass=''; // Enter your DB Password.
	$dataBaseName='webexpertdeveloper'; // Enter your Database Name.
	$dbh = new PDO('OCI:dbname='.$dataBaseName.'charset=UTF-8', $user, $pass);
	echo "Connection Successful";
?>

If there are any connection errors, a PDOException object will be thrown. You may catch the exception if you want to handle the error condition. For that you have to use below example you have to handle exception using try-catch .

<?php
	try
	{
		$user='root'; // Enter your DB User Name.
		$pass=''; // Enter your DB Password.
		$dataBaseName='webexpertdeveloper'; // Enter your Database Name.
		$dbh = new PDO('OCI:dbname='.$dataBaseName.'charset=UTF-8', $user, $pass);
		echo "Connection Successful";
	}
	catch (PDOException $e)
	{
		print "Error!: " . $e->getMessage() . "
";
		die();
	}
?>

If any error occur then PDOException handle this and give you proper error message.

Closing a connection

<?php
	try
	{
		$user='root'; // Enter your DB User Name.
		$pass=''; // Enter your DB Password.
		$dataBaseName='webexpertdeveloper'; // Enter your Database Name.
		$dbh = new PDO('OCI:dbname='.$dataBaseName.'charset=UTF-8', $user, $pass,);
		echo "Connection Successful";
                $dbh = null; // It Will Close the connection
	}
	catch (PDOException $e)
	{
		print "Error!: " . $e->getMessage() . "
";
		die();
	}
?>