Posts

Showing posts from February, 2012

Looping in Store Procedure MySql

Summary: In this tutorial, you will learn how to use various loop statements including WHILE, REPEAT and LOOP to run a block of code repeatedly in MySQL.
MySQL stored programming language supports loop which allows you to process commands iteratively. The standard loops are discuss as follows
WHILE loop The syntax of while loop is as follows:

WHILE expression DO Statements END WHILE
First the while loop checks the expression, if it is true it will executes statement until the expression become false. Because while loop checks the expression before statements executed, it is often known as pretest loop. Here is an example of using while loop in stored procedure:

DELIMITER $$ DROP PROCEDURE IF EXISTS WhileLoopProc$$ CREATE PROCEDURE WhileLoopProc() BEGIN DECLARE x INT; DECLARE str VARCHAR(255); SET x = 1; SET str = ''; WHILE x <= 5 DO SET str = CONCAT(str,x,','); …

Objects as Associative Arrays

Image
Objects as Associative Arrays As you may know, the dot (.) operator can be used to access the [] operator used with arrays.
<script language="javascript" type="text/javascript"> <!-- // These are the same object.property object["property"] //--> </script> The important thing to notice is that in the object syntax the property is an identifier, whereas in the array syntax, it's a string. The obvious benefits of using an array syntax to access an object is because of the literal data type, you can easily concat strings and play around with them to access an object. For this to work with the standard syntax, an eval() would need to be used.
How do I loop through properties in an object? You need to use a for/in loop.
<script language="javascript" type="text/javascript"> <!-- testObj = { prop1:"hello", …

Subclasses and Superclasses

Image
Subclasses and Superclasses In Java and C++, there is an explicit concept of the class hierarchy. i.e. Every class can have a super class from which it inherits properties and methods. Any class can be extended, or sub-classed so the resulting subclass can inherit its parent's behavior. As we have seen, JavaScript supports prototype inheritance instead of class based. It's possible for inheritance to happen other ways, however.
The following is an example of inheritance through functions.
<script language="javascript" type="text/javascript"> <!-- // thanks to webreference function superClass() { this.supertest = superTest; //attach method superTest } function subClass() { this.inheritFrom = superClass; this.inheritFrom(); this.subtest = subTest; //attach method subTest } function superTest() { return "superTest"; } function subTest() { return "…

Object Constructor and prototyping

Image
Object Constructor and prototyping In the world of OOP, the previous ways of defining an object is too limiting in many situations. We need a way to create an object "type" that can be used multiple times without having to redefine the object every time to meet each particular instance's needs. The standard way to achieve this is to use the Object Constructor function.
An object constructor is merely a regular JavaScript function, so it's just as robust (ie: define parameters, call other functions etc). The difference between the two is that a constructor function is called via the new operator (which you'll see below). By basing our object definition on the function syntax, we get its robustness as well.
Lets use a real world item "cat" as an example. A property of a cat may be its color or name. A method may be to "meeyow". The important thing to realize, however is that …

JavaScript and Object Oriented Programming (OOP)

Image
JavaScript and Object Oriented Programming (OOP)Credits: This tutorial is written and contributed by Tim Scarfe. Edited by JavaScriptKit.com for content/ structure. Please see footnote for more information on author.
JavaScript is an excellent language to write object oriented web applications. It can support OOP because it supports inheritance through prototyping as well as properties and methods. Many developers cast off JS as a suitable OOP language because they are so used to the class style of C# and Java. Many people don't realize that JavaScript supports inheritance. When you write object-oriented code it instantly gives you power; you can write code that can be re-used and that is encapsulated.
What's so great about objects? Objects work so well because they act just like real life objects- objects have properties and methods. So if we were talking about a lamp, a property of it m…

[mysql] 5 step create and grant mysql user

Image
1. Login to mysql using user root.
mysql -u root -p     enter your mysql password if needed. if login success, continue to the next step.

2. Use database mysql.
use mysql;

3. Create user root1 at all host...
create user 'root1'@'%' identified by 'password';
if you want to create user just for localhost ... the code must be like this : create user 'root1'@'localhost' identified by 'password';
4. Once you succeed create a new user, clear and reloads the privileges from the grant tables in the Mysql database with the following command.
flush privileges;
5. Last step, grant all privileges to the user that was created.
grant all privileges on *.* to root1@'%' identified by '' with grant option;