mysql queries to add simple prodcts in magento - mysql

Any one can help me to insert 1000 products of one database table into magento
I have one database table of product i want to insert all products of this table into magento store using mysql queries
Database Table Structure
CREATE TABLE IF NOT EXISTS `product` (
`id` int(11) NOT NULL,
`title` text NOT NULL,
`author` text NOT NULL,
`isbn13` bigint(13) NOT NULL,
`isbn10` varchar(10) NOT NULL,
`rank` varchar(10) NOT NULL,
`pic` varchar(25) NOT NULL,
`price` int(10) NOT NULL,
`publicationdate` varchar(10) NOT NULL,
`publisher` varchar(255) NOT NULL,
`desc1` text NOT NULL,
`cat` varchar(25) NOT NULL
)

To ensure that your data goes in correctly, you probably should use the Magento import feature , the official tutorial is available here.
If you attempt to do it via a direct mysql insert you may end up missing some of the EAV data that Magento requires...
If you need something a little faster, then you can use Magmi to import the data.
I am using Magmi on a daily basis to import/update around 3500 configurable and simple products without any issues.

Related

What is the best way to analyse data from a .sql file without a connection to a database?

I need to analyse data, without a database engine, from a .sql file that contains only 2 types of commands that create relational tables (i.e CREATE TABLE and INSERT INTO). I'm not sure how i can analyse the data without connecting to a database.
For example, the Python module sqlite3, required you to connect to .db.
Below is an example of the commands within the .sql file. Any ideas would be appreciated!
CREATE TABLE `sales` (
`month` smallint(6) NOT NULL,
`quarter` varchar(30) collate latin1_general_ci NOT NULL,
`year` smallint(6) NOT NULL,
`sales` decimal(10,4) NOT NULL,
`cost` decimal(10,4) NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

How do i create in a table in phpmyadmin?

Whenever I go to sql in phpmyadmin to create a table, I put this code in:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_up_date` date NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
it says:#1046 - No database selected
but when I put:
CREATE DATABASE data;
USE data;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`sign_up_date` date NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
it says that it could not create the database?
Step 1: Choose an existing Database or create a new Database.
Step 2: Choose the SQL tab and add your code to create a table.
One server can contain multiple databases. If you login into PHPMyAdmin, you choose a server to login to. After you've logged in, you have to select your database to be able to make changes to it.
So you don't need to create a database. You just need to select it. You can do that with the USE <databasename> statement, or though the PHPMyAdmin interface. In your second snippet, you already used have the USE statement. You just need to remove the CREATE DATABASE statement.
Same goes for creating the table, by the way. PHPMyAdmin provides an interface to add a table field by field without having to write the SQL for it. Although it can't hurt to know the syntax, of course.
Since you have got your sql statement, then just go to
phpMyAdmin > login (if there is need for it) > select database you want to use,
find it in Right Hand Side , example 'test'. tehn simply just find the
tab named sql and click it, after that just paste your statements

Storing customer specific details in MYSQL? Without new tables

I'm looking at storing customer details upon registering for my service, the service in question is a booking system, each user needs to have his/her own calender system which keeps records of all bookings (arrival data/time, name , price etc) i can envision a way of storing all this unique user information in a single table linked by only userID?
CREATE TABLE IF NOT EXISTS `bookings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`room_number` varchar(50) NOT NULL,
`name` varchar(20) NOT NULL,
`arrival` date NOT NULL,
`depart` date NOT NULL,
`nights` int(11) NOT NULL,
`price` decimal(11,2) NOT NULL,
`date_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
Each user would need to store this information? surely i would need to create a whole new table for each user? (Which i know is just plain slow and wrong).
You don't want to store a separate table for each user (except under some very specific requirements which are rather unusual). Your table is missing a userId. Something like:
CREATE TABLE IF NOT EXISTS `bookings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`UserId` int(11) NOT NULL,
`room_number` varchar(50) NOT NULL,
`name` varchar(20) NOT NULL,
`arrival` date NOT NULL,
`depart` date NOT NULL,
`nights` int(11) NOT NULL,
`price` decimal(11,2) NOT NULL,
`date_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (UserId) references users(UserId)
);
Don't worry about the number of rows in the table. SQL is designed to handle millions of rows for most applications. In fact, splitting the data among multiple tables would introduce some major problems with performance (notably partially filled pages) that could greatly reduce performance.

mysql table design, divide or all in one table?

I have table house
CREATE TABLE `house`
`idhouse` int(11) NOT NULL AUTO_INCREMENT,
`type` mediumint(2) DEFAULT NULL,
`address` varchar(5) DEFAULT NULL,
`county` varchar(5) ...
Now, I have the ads functionality. So want to bring the house into ads
Method 1 (directly add columns for adds)
CREATE TABLE `house`
`idhouse` int(11) NOT NULL AUTO_INCREMENT,
`type` mediumint(2) DEFAULT NULL,
`address` varchar(5) DEFAULT NULL,
`county` varchar(5) ...
`ad_type` mediumint(2) DEFAULT NULL,
`ad_urgency` int(11) DEFAULT NULL,
`ad_status` int(11) DEFAULT NULL,
Method 2 (normalization, split it into table Ads)
CREATE TABLE `house`
`idhouse` int(11) NOT NULL AUTO_INCREMENT,
`type` mediumint(2) DEFAULT NULL,
`address` varchar(5) DEFAULT NULL,
`county` varchar(5) ...
CREATE TABLE `Ads`
`idAds` int(11) NOT NULL AUTO_INCREMENT,
`idhouse` int(11) NOT NULL AUTO_INCREMENT,
`ad_type` mediumint(2) DEFAULT NULL,
`ad_urgency` int(11) DEFAULT NULL,
`ad_status` int(11) DEFAULT NULL,
I'll do more SELECT (90%) operations instead of INSERT, UPDATE, DELETE (10%)
SELECT operations will ALL be based on variables such ad_type, ad_urgency, and ad_status.
I'm taking consideration of performance a lot.
Which method should I use ?
Is using method 1 (SELECT without joining) is faster than method 2 (SELECT with joining) ?
If faster, by how much ? A lot ?
Normalization has alot of advantages.
It helps you avoid redundancies.
It makes your database structure flexible.
It helps you avoid anomalies.
Complex queries are usually easier.
It minimizes your data
...and a few more.
The speed of queries cannot be easily determined by the data structure alone, it is affected by many different aspects like database configuration, server hardware, indexing, data load and much more.
But since less data usually means faster queries (with or without joins): Go for the normalzied approach. The database admin taking the system over will thank you.

How to read different entries from database for multilanguage site with Codeigniter?

I couldn't find answer for this question... I'm making a multilanguage web site based on Codeigniter and MySQL database. For the static language texts I'm using the built in lang function and according the first segment of the URL /en/ /fr/... I'm loading the appropriate language file, but how do I load and display the corresponding data from the database? How do I even keep the data in the database? I have products table and half of the entries are numerical values, but the other half are texts that should be kept in 2 or 3 languages.
I have my logic to keep name_en and name_fr, description_en and description_fr... all of these in the same table, so I will double those rows as I add new language.
When I will be making a Select query, I will be passing the segment "en" to the query and concanate at the end of name_ or description_ so it would become name_en or description_fr or category_es.
I hope that there is much better way, and some of you who have already worked with this will help me through.
I am usign two table for multilangage support. First table include item fields. For example date, vote and etc. Second table for languages fields.
CREATE TABLE `item` (
`item_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`nested_category_id` int(11) DEFAULT NULL,
`image_file` varchar(100) NOT NULL,
`date` varchar(0) DEFAULT NULL,
PRIMARY KEY (`item_id`)
);
CREATE TABLE `item_lang` (
`item_lang_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`lang_id` varchar(2) NOT NULL,
`item_id` int(11) unsigned NOT NULL,
`url_name` varchar(255) NOT NULL DEFAULT '',
`meta_title` varchar(255) DEFAULT NULL,
`meta_description` text,
`meta_keywords` varchar(255) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`title` varchar(255) DEFAULT NULL,
`description` text,
PRIMARY KEY (`item_lang_id`)
);
If you need a row try like this.
function get_row( $id, $lg='tr'){
$arr = array($id, $lg);
$sql = " SELECT ".$this->_table.".*, ".$this->_table_lang.".*
FROM ".$this->_table."
LEFT JOIN ".$this->_table_lang."
ON ".$this->_table.".".$this->_table."_id = ".$this->_table_lang.".".$this->_table."_id
WHERE ".$this->_table.".".$this->_table."_id = ?
AND ".$this->_table_lang.".lang_id=?";
$data = $this->db->query($sql, $arr);
return ($data->row());
}