Some interesting Bugs in php

<?
if(isset($_REQUEST['submit']))
echo "<pre>";
print_r($_POST);
echo "</pre>"

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="POST">
<input type="hidden" name="test.one" value="1" />
<input type="hidden" name="test#two" value="2" />
<input type="submit" name="submit Me" value="Click me" />
</form>

</body>
</html>

<?
echo date('Y-m-d', strtotime('first monday jan 2007'));
echo "<br>";

echo date('Y-m-d', strtotime('first monday feb 2007'));
echo "<br>";

echo date('Y-m-d', strtotime('first thursday feb 2007'));
echo "<br>";

echo date('Y-m-d', strtotime('first thursday jan 2007'));
echo "<br>";
?>

<?
preg_match('/(.{0,20})$/us', " ", $m);
var_export($m);
?>

<?
for ($char="A";$char<="Z";$char++)
{
echo "$char - ";
}
?>

<?
$test = "X\\X?asdasdasd\\asdasd.*";

echo $tt=preg_quote($test);
//echo preg_match("/X\\X/", $tt)."\n";
?>

pregquote

<?
$test = "X\\X?asdasdasd\\asdasd.*";

echo $tt=preg_quote($test);
//echo preg_match("/X\\X/", $tt)."\n";
?>

How does one configure PHP to use Oracle?

Follow these steps to prepare your PHP installation for connecting to Oracle databases:
Download PHP from www.php.net, install as per the install.txt file, and test if everything is working.
Install the Oracle Client (or Server) software on your machine and configure SQL*Net to connect to your database(s). See the SQL*Net FAQ for details.
Edit your php.ini file and uncomment the following two lines (only if your version shipped with pre-compiled extension modules):
;extension = php_oci8.dll
;extension = php_oracle.dll
... otherwise, compile PHP with the following options:
--with-oracle=/path/to/oracle/home/dir
--with-oci8=/path/to/oracle/home/dir
Ensure that your "extension_dir" parameter (in php.ini) points to the location where the above extension files reside.
Write a small program to test connectivity - see the next question.

Refer:
http://www.orafaq.com/faq/how_does_one_configure_php_to_use_oracle
http://www.weberdev.com/ViewArticle/Simple-Connection-to-Oracle-with-PHP

How does one configure PHP to use Oracle?

Submitted by admin on Sun, 2005-11-06 02:27.
Follow these steps to prepare your PHP installation for connecting to Oracle databases:
Download PHP from www.php.net, install as per the install.txt file, and test if everything is working.
Install the Oracle Client (or Server) software on your machine and configure SQL*Net to connect to your database(s). See the SQL*Net FAQ for details.
Edit your php.ini file and uncomment the following two lines (only if your version shipped with pre-compiled extension modules):
;extension = php_oci8.dll
;extension = php_oracle.dll
... otherwise, compile PHP with the following options:
--with-oracle=/path/to/oracle/home/dir
--with-oci8=/path/to/oracle/home/dir
Ensure that your "extension_dir" parameter (in php.ini) points to the location where the above extension files reside.
Write a small program to test connectivity - see the next question.

Mysql Questions..

1.An INNER JOIN does a full join, just like the first example, and the word OUTER may be added after the word LEFT or RIGHT.

2. What are the differences between drop a table and truncate a table?
Delete a Table or DatabaseTo delete a table (the table structure, attributes, and indexes will also be deleted).What if we only want to get rid of the data inside a table, and not the table itself? Use the TRUNCATE TABLE command (deletes only the data inside the table).

3.How can we repair a mysql table?
The syntex for repairing a mysql table is
REPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]
This command will repair the table specified
if the quick is given the mysql will do a repair of only the index tree if the extended is given it will create index row by row.

4.How can we find the number of rows in a table using mysql?
>SELECT COUNT(*) FROM table_name; but if u r particular about no of rows with some special result do this
>SELECT [colms],COUNT(*) FROM table_name [where u put conditions];

5.How many ways we can we find the current date using mysql?
SELECT CURDATE();
CURRENT_DATE() = CURDATE()
for time use
SELECT CURTIME();
CURRENT_TIME() = CURTIME()

Php Questions...

1.How can we know the number of days between two given dates using mysql? select DIFFDATE( NOW(), 'yyyy-mm-dd' );

2.How can I load data from a text file into a table?
The mysql provides a LOAD DATA INFILE syntax. U can load data from a file.

3.What is meant by MIME?
Multipurpose Internet Mail Extensions. WWW's ability to recognise and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types. ...

4.What are the difference between abstract class and interface?
Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.
Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

batch file with php

How to run window batch file in php?
Step 1
Creata bacth file like that

mkdir %1

save the file name as test.bat


step-2

php program
<?
shell_exec("test.bat india");
?>

Run the php automaticaly create one floder

How to take the selected tables dump using command prompt -Mysql

mysqldump --add-drop-table -u root -p database_name table1 table2 table3 >dump.sql

php Substring Examples

Use substr( ) to select your substrings:

$substring = substr($string,$start,$length);
$username = substr($_REQUEST['username'],0,8);

Php Questions

Object-oriented questions

  1. Class definitions must end with a semi-colon: true or false?

    True
    False


  2. Calling __clone() is not allowed: true or false?

    True
    False


  3. Abstract classes cannot be instantiated: true or false?

    True
    False


  4. You can use objects as an array in foreach loops: true or false?

    True
    False


  5. Private variables can only be accessed from within the class that defined them, or any subclass of it: true or false?

    True
    False


Function questions

  1. What function would you use to tell the browser the content type of the data being output?

    imagejpeg()
    imageoutput()
    flush()
    header()
    imageload()


  2. What parameters does the func_get_args() function take?

    0: It doesn't take any parameters
    1: name of function to check
    2: name of function to check, boolean "count optional arguments"


  3. What does the array_shift() function do?

    Add an element to an array
    Removes an element from an array
    Shifts all elements towards the back of the array
    Switches array keys and values
    Clears the array


  4. What function would you use to delete a file?

    unlink()
    delete()
    fdelete()
    file_delete()


  5. What is the difference between exec() and pcntl_exec()?

    Nothing, they are the same
    pcntl_exec() forks a new process
    pcntl_exec() can only be called from a child process
    None of the above


  6. If $string is "Hello, world!", how long would the output of sha1($string) be?

    It varies
    16 characters
    20 characters
    24 characters
    32 characters
    40 characters


  7. If the input of chr() is $a and the output is $b, what function would take input $b and produce output $a?

    chr()
    rch()
    ord()
    strrev()
    chr(chr())
    chrrev()


  8. If $a is "Hello, world!", is this statement true or false: md5($a) === md5($a)

    True
    False


  9. Which function returns true when magic quotes are turned on?

    get_magic_quotes()
    magic_quotes_get()
    magic_quotes()
    get_magic_quotes_gpc()
    get_quotes()


  10. The functions get_required_files() and get_included_files() are identical, true or false?

    True
    False


  11. If $arr was an array of ten string elements with specific keys, what would array_values(ksort($arr)) do?

    Create a new array of just the values, then sort by the keys
    Create a new array of just the values, then ignore the sort as there are no keys
    Sort the array by key, then return a new array with just the values
    Trigger a warning
    None of the above


  12. What is the return value of array_unique()?

    Boolean
    Integer
    Array
    It varies
    None of the above


Miscellaneous questions

  1. Output buffering compression is...

    High on CPU resources, low on network resources
    Low on CPU resources, high on network resources
    High on CPU resources, high on network resources
    Low on CPU resources, low on network resources


  2. You can exit a PHP code block (that is, use ?> to go back to HTML mode) while in the middle of a class definition: true or false?

    True
    False


  3. Examine this code - on which line is there an error?


    <?php
    class dog {
    public function bark() {
    echo "Woof!";
    }
    };

    $foo = new dog;
    $foo->bark();
    ?>



    Line 2 (class dog)
    Line 3 (public function bark())
    Line 4 (echo "Woof!")
    Line 6 ( }; )
    Line 8 ($foo = new dog)
    Line 9 ($foo->bark())
    There is no error


  4. True or false: to ensure maximum portability for your scripts, you should try to use exceptions.

    True
    False


  5. What directive would you change in your php.ini file to disable assert()?

    assert
    assert.active
    assert.enable
    assert.assert
    assert.options
    None of the above


  6. Which of these statements is true?

    PHP 4 had object orientation, but not extensions
    PHP 4 had extensions, but not object orientation
    PHP 4 had object orientation, but not exceptions
    PHP 4 had exceptions, but not object orientation
    None of the above

Mathematical questions

  1. "10" == 10: true or false?

    True
    False


  2. "10" === 10: true or false?

    True
    False


  3. "10" !== 10: true or false?

    True
    False


  4. 10 === 010: true or false?

    True
    False


  5. 010 >= 10: true or false?

    True
    False


  6. What is the value of this sum: 5 * 6 / 2 + 2 * 3

    0
    3
    4
    19
    21
    24
    29
    51


Database questions

  1. This SQL statement is valid "SELECT ID, Name FROM some_table ORDER BY Name WHERE ID < 100" - true or false?

    True
    False


  2. Joins are fastest when done using which data type:

    INT
    JOIN
    FLOAT
    INDEX
    CHAR
    VARCHAR
    CACHE
    None of the above


  3. SQLite is compiled into PHP 5 by default: true or false?

    True
    False


  4. All five parameters to mysql_connect() are optional, true or false?

    True
    False


  5. What is the best description of a normalised table?

    One where optimal data types are used
    One where data is not repeated
    One where the schema is valid
    One that is properly indexed
    One that has been defragmented


String questions

  1. If $string is set to "Hello, world!", what is $string{4}?

    H
    e
    l
    o
    w
    r
    d


  2. What is the case-insensitive version of the strcmp() function?

    strcmpi()
    stricmp()
    strcasecmp()
    istrcmp()


  3. How many parameters can the trim() function take?

    0
    1
    2
    3
    4+


  4. The parse_str() function...

    Checks a string of PHP code is valid
    Checks a string of PHP code is valid, then executes it
    Searches a string for non-English characters
    Converts the contents of a string into variables


  5. What will this function return: preg_match("[A-Za-z0-9_]*", "This_is_a_test")

    True
    False


  6. What would implode(".", explode(",", $string)) do?

    Replace all full stops (periods) with spaces
    Replace all full stops with commas
    Delete all full stops
    None of the above

PHP MAGIC CONSTANTS

A few "magical" PHP constants :

NameDescription
__LINE__ The current line number of the file.
__FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path whereas in older versions it contained relative path under some circumstances.
__FUNCTION__ The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__CLASS__ The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__METHOD__ The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).