search
top

Get database connection details in Magento

I am writing here an important code snippet for getting the database connection details used in Magento $config = Mage::getConfig()->getResourceConnectionConfig("default_setup"); $_host = $config->host; $_uname = $config->username; $_pass = $config->password; $_dbname = $config->dbname; echo $_host; ///likewise
read more

Filters in Query in Magento

Hello All, When we are filtering data in Magento, time occurs when we want to fetch result after filters like Not equal, greater than, less than, etc. The addFieldToFilter method’s second parameter is used for this. It supports an alternate syntax where, instead of passing in a string, you pass in a single element Array. The key of this array is the type of comparison you want to make. The value...
read more

MySQL Database restore

I have already listed the PHP script to generate backup of database in one of my earlier post. I am listing here the PHP script to restore database from mysql database file. <?php /* Database Restore */ $username = "dbusername"; //database username $password = 'dbpass'; //database password $hostname = "localhost"; //host $dbname = "dbname"; //database name...
read more

Insert and Retrieve file with MySQL

Some of you might be knowing that there is a functionality in MySQL database for storing files and retrieving the same. This is mainly used when we need to reduce response time for retrieving and using files in our application. I am listing here the method for inserting image file in and retrieving image file from MySQL database using PHP. 1) For inserting data into MySQL you need to convert the image...
read more

Database Backup

I am listing here the PHP script to generate backup of database. <?php /* Database Backup */ $username = "dbusername"; //database username $password = 'dbpass'; //database password $hostname = "localhost"; //host $dbname = "dbname"; //databse name $sConnString = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $name...
read more

Queries in Magento

I am describing here the method for executing custom MySQL queries in Magento. <?php //select query $read = Mage::getSingleton('core/resource')->getConnection('core_read'); //make connection $qry = "select name FROM user_data WHERE id=1 LIMIT 1 "; //query $res = $read->fetchRow($qry); //fetch row $name = $res['name']; //outputs name ...
read more

Connect different database from Magento

Some of you might have worked on Magento. I am listing here points for connecting another database from Magento. 1) Suppose your database for Magento Project is named ‘magento’. 2) There is one other database named ‘wp’. 3) For using this database inside Magento, you need to setup connection in ‘config.xml’ file which resides in ‘urmagentodirectory/app/etc’ 4) In ‘config.xml’ there...
read more

top