Tuesday, July 7, 2009

Mysql

Mysql

When to use MySQL

Why would you use MySQL over PostgreSQL? First, we need to consider the needs of the applications in terms of database requirements. If I want to create a Web application and performance is an issue, MySQL will be my choice because it’s fast and designed to work well with Web-based servers. However, if I want to create another application that demands transactions and foreign key references, PostgreSQL is the choice.


MySQL is relatively faster than PostgreSQL.

Database design will be simpler.

You can create a basic Web-driven Web site.

MySQL’s replication has been thoroughly tested.

There’s no need for cleanups in MySQL (Vacuum).



Mysql was written in c and c++.

To know second max sal

Select sal from emp order by sal desc limit 1,1;

The Row Holding the Maximum of a Certain Column

SELECT article, dealer, price

FROM shop

WHERE price=(SELECT MAX(price) FROM shop);


1.What is MySQL?

MySql is a Relational database management system, provided from open source community. Currently fast growing and hight used RDBMS. MySql Developed by MySql AB.

2.What is Postgres?


3.What are the basic steps in setting up an Oracle system?

4.What is a stored procedure, and which databases support it?

Set of sql statements. Mysql 5.0 supports procedures.

5.What is RMAN?

6.What is the TDS protocol?

7.What is required to connect to an oracle system remotely?

8.In MySQL, how do I create a database?

9.In MySQL, how do I grant access to a user to a specific database with read only permissions?

10.In MySQL, what table type is required for foreign keys to work?

InnoDB

11.Constraint: primary key. Foreign key, unique key

12.Connecting to server:


shell> mysql -h host -u user -p

Enter password: ********

SELECT VERSION(), CURRENT_DATE;

Use the SHOW statement to find out what databases currently exist on the server:

mysql> SHOW DATABASES;

If the test database exists, try to access it:

mysql> USE test

Database changed


mysql> GRANT ALL ON menagerie.* TO 'your_mysql_name'@'your_client_host';

where your_mysql_name is the MySQL username assigned to you and your_client_host is the host from which you connect to the server.


CREATE DATABASE menagerie;


USE menagerie

or

shell> mysql -h host -u user -p menagerie

Enter password: ********

Note that menagerie is not your password on the command just shown. If you want to supply your password on the command line after the -p option, you must do so with no intervening space (for example, as -pmypassword, not as -p mypassword). However, putting your password on the command line is not recommended, because doing so exposes it to snooping by other users logged in on your machine.

SHOW TABLES;

DESCRIBE pet;

LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;


mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet

-> LINES TERMINATED BY '\r\n';

Some characteristics of extended regular expressions are:

· '.' matches any single character.

· A character class '[...]' matches any character within the brackets. For example, '[abc]' matches 'a', 'b', or 'c'. To name a range of characters, use a dash. '[a-z]' matches any letter, whereas '[0-9]' matches any digit.

· '*' matches zero or more instances of the thing preceding it. For example, 'x*' matches any number of 'x' characters, '[0-9]*' matches any number of digits, and '.*' matches any number of anything.

· A REGEXP pattern match succeed if the pattern matches anywhere in the value being tested. (This differs from a LIKE pattern match, which succeeds only if the pattern matches the entire value.)

· To anchor a pattern so that it must match the beginning or end of the value being tested, use '^' at the beginning or '$' at the end of the pattern.

To demonstrate how extended regular expressions work, the LIKE queries shown previously are rewritten here to use REGEXP.

To find names beginning with 'b', use '^' to match the beginning of the name:

mysql> SELECT * FROM pet WHERE name REGEXP '^b';


1.What are the different types of joins?

Different Types of Joins-

Inner Join

Outer Join - Right Outer Join

Left Outer Join

Cross Join


2.Explain normalization with examples.

The process of converting complex data structures into simple, stable data structures


3.What cursor type do you use to retrieve multiple recordsets?

REF Cursor


4.Diffrence between a “where” clause and a “having” clause

1.”where” is used to filter records returned by “Select”

2.”where” appears before group by clause

3.In “where” we cannot use aggrigate functions like where count(*)>2 etc

4.”having” appears after group by clause

5.”having” is used to filter records returned by “Group by”

6.In”Having” we can use aggrigate functions like where count(*)>2 etc


5.What is the difference between “procedure” and “function”?


6.How will you copy the structure of a table without copying the data?

select top 0 * into xyz from try


7.How to find out the database name from SQL*PLUS command prompt?


8.Tadeoffs with having indexes


9.Talk about “Exception Handling” in PL/SQL?


10.What is the diference between “NULL in C” and “NULL in Oracle?”


11.What is Pro*C? What is OCI?


12.Give some examples of Analytical functions.


13.What is the difference between “translate” and “replace”?


14.What is DYNAMIC SQL method 4?


15.How to remove duplicate records from a table?


16.What is the use of ANALYZing the tables?


17.How to run SQL script from a Unix Shell?


18.What is a “transaction”? Why are they necessary?


19.Explain Normalizationa dn Denormalization with examples.


20.When do you get contraint violtaion? What are the types of constraints?


21.How to convert RAW datatype into TEXT?


22.Difference - Primary Key and Aggregate Key


23.How functional dependency is related to database table design?


24.What is a “trigger”?

it’s a piece of sql that is activitied when a certain event happens.


25.Why can a “group by” or “order by” clause be expensive to process?


26.What are “HINTS”? What is “index covering” of a query?


27.What is a VIEW? How to get script for a view?

A Database View is a subset of the database sorted and displayed in a particular way.


28.What are the Large object types suported by Oracle?


29.What is SQL*Loader?


30.Difference between “VARCHAR” and “VARCHAR2″ datatypes.

Difference between Varchar and Varchar2 is both are variable length but only 2000 bytes of character of data can be store in varchar where as 4000 bytes of character of data can be store in varchar2.


31.What is the difference among “dropping a table”, “truncating a table” and “deleting all records” from a table.

Dropping : (Table structure + Data are deleted), Invalidates the dependent objects ,Drops the indexes

Truncating: (Data alone deleted), Performs an automatic commit, Faster than delete

Delete : (Data alone deleted), Doesn’t perform automatic commit


32.Difference between “ORACLE” and “MICROSOFT ACCESS” databases.

33.How to create a database link?

34.What is SQL?

SQL stands for 'Structured Query Language'.


35.What is SELECT statement?

The SELECT statement lets you select a set of values from a table in a database. The values selected from the database table would depend on the various conditions that are specified in the SQL query.


36.How can you compare a part of the name rather than the entire name?

SELECT * FROM people WHERE empname LIKE '%ab%'

Would return a recordset with records consisting empname the sequence 'ab' in em


37.What is the INSERT statement?

The INSERT statement lets you insert information into a database

38.How could I get distinct entries from a table?

The SELECT statement in conjunction with DISTINCT lets you select a set of distinct values from a table in a database. The values selected from the database table would of course depend on the various conditions that are specified in the SQL query. Example

SELECT DISTINCT empname FROM emptable


39.How to get the results of a Query sorted in any order?

You can sort the results and return the sorted results to your program by using ORDER BY keyword thus saving you the pain of carrying out the sorting yourself. The ORDER BY keyword is used for sorting.

SELECT empname, age, city FROM emptable ORDER BY empname


40.How can I find the total number of records in a table?

You could use the COUNT keyword , example


SELECT COUNT(*) FROM emp WHERE age>40


41.What is GROUP BY?

The GROUP BY keywords have been added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called. Without the GROUP BY functionality, finding the sum for each individual group of column values was not possible.


42.What is the difference among "dropping a table", "truncating a table" and "deleting all records" from a table.

Dropping : (Table structure + Data are deleted), Invalidates the dependent objects ,Drops the indexes

Truncating: (Data alone deleted), Performs an automatic commit, Faster than delete

Delete : (Data alone deleted), Doesn’t perform automatic commit


43.What are the Large object types suported by Oracle?

Blob and Clob.


44. Difference between a "where" clause and a "having" clause.

Having clause is used only with group functions whereas Where is not used with 45. What's the difference between a primary key and a unique key?

Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only.


46. What are cursors? Explain different types of cursors. What are the disadvantages of cursors? How can you avoid cursors?

Cursors allow row-by-row prcessing of the resultsets.

Types of cursors: Static, Dynamic, Forward-only, Keyset-driven. See books online for more information.

Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.

Most of the times, set based operations can be used instead of cursors

Monday, June 1, 2009

PHP

1.What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?

When you want to send short or small data,not containing ASCII characters, then you can use “GET” Method. But for long data sending say more then 100 character you can use “POST” method. Once most imp diff is when you are sending the form with

“Get” method. You can see the output which you are sending in the addressbar. Whereas if you send the form with “POST” method then user can not see that information.


2.How can we submit a form without a submit button?

I can submit a form in many ways, for e.g.

1. When user click on checkbox, or drop down

2. When user click on radio button

3. At the end of the form I will type “Click here

to submit” & link text to the processing file


3.What is the difference between mysql_fetch_object and mysql_fetch_array?

mysql_fetch_object() is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names). Note: Field names returned by this function are case-sensitive.

field;

/* this is invalid */

echo $row->0;


4.What is the difference between $message and $$message?

1. $message is variable whereas $$message is Dynamic variable.

eg.

$user=”bob”

is equivalent to

$holder=”user”;

$$holder=”bob”;


5.What are the differences between require and include, include_once?

The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include produces a warning message whereas require produces a Fatal errors.


6.Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?

yes we can use. If abc.php contains classes or functions it will give errors that same class or function is already existed. Otherwise it won’t give any error.


7.How can I execute a PHP script using command line?

Through php parse you can execute PHP script using command line. By default location of php parser is /var/www/html so set the path of this directory and just use as following

#php sample.php


8.What is meant by nl2br()?

nl2br() inserts html in string

echo nl2br(”god bless \n you”);

output

god bless

you


9.What are the current versions of apache, PHP, and mysql?

Php 5, mysql 5, Apache 2


10.What are the reasons for selecting lamp (linux, apache, mysql, PHP) instead of combination of other software programmes, servers and operating systems?

All are open source.


11.How can we get second of the current time using date function?

date(‘s’)


12.What is the difference between the functions unlink and unset?

unlink is a function for file system handling. It will simply delete the file in context

unset will set UNSET the variable. e.g


13.How can we destroy the cookie?
Set the cookie in past


14.How many ways we can pass the variable through the navigation between the pages?

Sessions, cookies, hidden variables, get, post


15.What are the different functions in sorting an array?

Usort, ksort, uksort, asort

16.In how many ways we can retrieve the date in the result set of mysql using PHP?

mysql> SELECT DATE_ADD('1998-01-02', INTERVAL 31 DAY);

-> '1998-02-02'

mysql> SELECT ADDDATE('1998-01-02', INTERVAL 31 DAY);

*

'1998-02-02'


17.Who is the father of PHP and explain the changes in PHP versions?

Rasmus Lerdorf - father of PHP


18.How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’ using regular expression of PHP?

$s="http://info@abc.com";

$z=preg_split("/@/", $s);

echo $z[1];


19.How can we create a database using PHP and mysql?

mysql_create_db(“database”)


20.What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?

Total 5 types of tables we can create

1. MyISAM

2. Heap

3. Merge

4. INNO DB

5. ISAM

MyISAM is the default storage engine as of MySQL 3.23.


21.Functions in IMAP, POP3 AND LDAP?

imap_body — Read the message body

imap_check — Check current mailbox

imap_delete — Mark a message for deletion from current mailbox

imap_mail — Send an email message



22.Suppose your Zend engine supports the mode Then how can u configure your PHP Zend engine to support mode ?


file(filename)-> Reads entire file in an array


In php.ini


Ini_get(include_path):will get the include path


short_open_tag: Allows short tags to be parsed. ( as apposed to
and ?>).

Output Buffering: Allows header line s to be sent after HTML has already been sent to

server.

Max_execution_time: time limit for script execution in seconds.

Variable_order: EGPCS

Register_globals: From 4.2 it is off


23.Shopping cart online validation i.e. how can we configure Paypal, etc.?

24.Draw the architecture of Zend engine?

25.How can we encrypt and decrypt a data present in a mysql table using mysql?

AES_ENCRYPT() and AES_DECRYPT()


26.How can we encrypt the username and password using PHP?

Crypt()


27.What are the features and advantages of object-oriented programming?

28.What are the differences between procedure-oriented languages and object-oriented languages?

29.What is the use of friend function?

30.What are the differences between public, private, protected, static, transient, final and volatile?

31.What are the different types of errors in PHP?

Three are three types of errors 1) Fatal errors 2) Parser errors 3) Startup errors.

Warnings, notices

32.What is the functionality of the function strstr and stristr?

string strstr ( string str1, string str2) this function search the string str1 for the first occurrence of the string str2 and returns the part of the string str1 from the first occurrence of the string str2. This function is case-sensitive and for case-insensitive search use stristr() function.

33.What are the differences between PHP 3 and PHP 4 and PHP 5?

34.How can we convert asp pages to PHP pages?

35.What is the functionality of the function htmlentities?

htmlspecialchars : Convert some special characters to HTML entities (Only the most widley used)

htmlentities : Convert ALL special characters to HTML entities

36.How can we convert the time zones using PHP?

37.What is meant by urlencode and urldocode?

string urlencode(str)

where str contains a string like this “hello world” and the return value will be URL encoded and can be use to append with URLs, normaly used to appned data for GET like someurl.com?var=hello%world

string urldocode(str)

this will simple decode the GET variable’s value

Like it echo (urldecode($_GET_VARS[var])) will o/p “Hello world”

38.How can we register the variables into a session?

session_register($ur_session_var);

39.How can we get the properties (size, type, width, height) of an image using PHP image functions?

getimagesize — Get the size of an image

image_type_to_extension — Get file extension for image type

imagesx — Get image width

imagesy — Get image height

40.How can we get the browser properties using PHP?

41.What is the maximum size of a file that can be uploaded using PHP and how can we change this?

42.How can we increase the execution time of a PHP script?

Use set_time_limit(int) where int is the number of seconds for

execution of the script. If it’s set to 0 it’s unlimited. Default value

is 30.

43.How can we take a backup of a mysql table and how can we restore it. ?

To backup: BACKUP TABLE tbl_name[,tbl_name…] TO ‘/path/to/backup/directory’

RESTORE TABLE tbl_name[,tbl_name…] FROM ‘/path/to/backup/directory’

mysqldump: Dumping Table Structure and Data

Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.

-t, –no-create-info

Don’t write table creation information (the CREATE TABLE statement).

-d, –no-data

Don’t write any row information for the table. This is very useful if you just want to get a dump of the structure for a table!

44.How can we optimize or increase the speed of a mysql select query?

45.How many ways can we get the value of current session id?

Session_id()

46.How can we destroy the session, how can we unset the variable of a session?

Session_unregister()

47.What is the difference between ereg_replace() and eregi_replace()?

48.How can we know the count/number of elements of an array?

2 ways

a) sizeof($urarray) This function is an alias of count()

b) count($urarray)

interestingly if u just pass a simple var instead of a an array it will return 1.

49.What is the PHP predefined variable that tells the What types of images that PHP supports?

imagetypes — Return the image types supported by this PHP build

This function returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. The following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM. To check for PNG support, for example, do this: Example 1. imagetypes() example

50.How can I know that a variable is a number or not using a JavaScript?

51.List out some tools through which we can draw E-R diagrams for mysql.

52.How can I retrieve values from one database server and store them in other database server using PHP?

53.List out the predefined classes in PHP?

Predefined Classes

Standard Defined Classes

These classes are defined in the standard set of functions included in the PHP build.

a. Directory

The class from which dir() is instantiated.

b.stdClass

2.Ming Defined Classes

These classes are defined in the Ming extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.

a.swfshape

b. swffill

c. swfgradient

d. swfbitmap

e. swftext

f. swftextfield

g. swffont

h. swfdisplayitem

i. swfmovie

j. swfbutton

k. swfaction

l. swfmorph

m. swfsprite

3. Oracle 8 Defined Classes

These classes are defined in the Oracle 8 extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.

a. OCI-Lob

b. OCI-Collection

4. qtdom Defined Classes

These classes are defined in the qtdom extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.

a. QDomDocument

b. QDomNode

54.How can I make a script that can be bilanguage (supports English, German)?

55.What are the difference between abstract class and interface?

56.How can we send mail using JavaScript?

function myfunction(form)

{

tdata=document.myform.tbox1.value;

location=”mailto:dep7abc@leeds.ac.uk?subject=”+tdata+”/MYFORM”;

return true;

}

57. PHP libraries

ADODB

XML RPC

PhpMailer


General


ERRORS IN PHP

Three types of errors are thete

1.

Fatal Error : Run time errors. Execution will be halted.

Making a call to function which does not exist

1.

Warnigns : Run Time warnings. Script Execution will not halted.

Warnings are generally come when using wrong parameter count for functions. Using Undefined variables.

1.

Notices : Run Time Notices. This indicate that the script has encountered something could indicate an error, but could also happen in normal course of running the script.