Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Sunday, May 3, 2015

Python, Django Initial Setup

There are plenty of resources available on the web for installing and configuring Python and Django.

This one is small set of commands for installation on what i have experienced while installing

1. Install Python as per your need - Either from Python website or PPM distribution of your OS if it provides the one. (I prefer package manager, since it gives you stable release that best works with your OS version)
2. Install Django - As said above for #Python
3. Database - Python by defaut comes with SQLite, but i prefer MySQL for its robust features

After all these, i stuck up all getting together - When you try to run server by issuing something like this python manage.py runserver and get any errors, try these:
4. sudo apt-get install libmysqlclient-dev
5. sudo apt-get install python-dev
6. sudo easy_install mysql-python

Now you can start server and access this to find default page http://127.0.0.1:8000/

Thursday, March 27, 2014

Sunday, March 17, 2013

MySQL - If Exists update else insert Query

INSERT INTO component_psar (tbl_id, row_nr, col_1, col_2, col_3, col_4, col_5, col_6, unit, add_info, fsar_lock)
VALUES('2', '1', '1', '1', '1', '1', '1', '1', '1', '1', 'N')
ON DUPLICATE KEY UPDATE col_1 = VALUES(col_1), col_2 = VALUES(col_2), col_3 = VALUES(col_3), col_4 = VALUES(col_4), col_5 = VALUES(col_5), col_6 = VALUES(col_6), unit = VALUES(unit), add_info = VALUES(add_info), fsar_lock = VALUES(fsar_lock)
The Checking key should be UNIQUE. Only if this query will work.
Refer : http://stackoverflow.com/questions/12639407/sql-if-exists-update-else-insert-syntax-error 

Save array as multiple fields in DB

Set id as an auto_increment primary key column in your table.
create table email (
    id int unsigned primary key auto_increment,
    cus_id int unsigned,
    email varchar(50)
);

insert into email (cus_id, email) values ('$cusid', '$email');
id will then take care of itself, all you have to do is leave it alone when inserting.
PHP code to do this in a loop:
foreach ($test as $cusid => $email) {
    $querystring = "insert into users (cus_id, email) values ('$cusid', '$email')";
    myqsli_query($querystring);
}