How can you access a COM object from a PHP page?How can we know the count/number of elements of an array?How session works (internal processing of session)?How many ways I can redirect a PHP page?How can I turn off MySQL strict mode? or Solving Incorrect integer value problem with MySQL 5 strict-modeExplain the changing file permission and ownership using PHP's chmod() function.Explain the difference between ereg_replace() and eregi_replace(). ~ Interview Questions & Answers
By utilizing the com_load and the dotnet_load respectively
you can incorporate COM objects and .NET libraries into your
PHP code, thus anytime you see "library code" in a question,
make sure you remember these two functions.
com_load — Creates a new reference to a COM component [deprecated]
Deprecated, use the OO syntax instead.
<?php
// do this
$obj = new COM($module);
// instead of this:
$obj = com_load($module);
?>
2 ways:
a) sizeof($array_name) - This function is an alias of count()
b) count($array_name) - This function returns the number of elements in an array.
Interestingly if you just pass a simple var instead of an array, count() will return 1.
6:49 PM
To start a session:
– session_start()
– Creates a session identifier
– Session identifier is passed between client and server either as a Cookie, or in GET parameters
Then, can create, access, and modify session variables:
– $_SESSION[session_var_name] = value;
– $_SESSION is only available once you call session_start()
– $local_variable = $_SESSION[session_var_name];
– Can check if session variable is set by using isset();
To end a session:
– session_destroy();
6:44 PM
a. Header function in PHP redirects to a new URL
Example:
<?php
header("Location: http://www.redirecturl.com/");
?>
b. http_redirect() is also used to redirect to a new page or URL.
Syntax
void http_redirect ( [string url [, array params [, bool session = FALSE [, int status]]]] )
Here, the URL is the path of the new page. params can be some query parameters followed by whether the session information needs to be passed and the custom response status code.
4:56 PM
This can be done in two ways...
Open your "my.ini" (my.cnf in linux) file within the MySQL installation directory, and look for the text "sql-mode".
Find:
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Replace with:
# Set the SQL mode to strict
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Or, you can run an SQL query within your database management tool, such as phpMyAdmin:
SET @global.sql_mode= '';
10:56 PM
Chmod() is used for changing permissions on a file.
Syntax:
Chmod(file, mode)
Mode here specifies the permissions as follows:
* The first number is always zero
* The second number specifies permissions for the owner
* The third number specifies permissions for the owner's user group
* The fourth number specifies permissions for everybody else
Possible values (to set multiple permissions, add up the following numbers)
* 1 = execute permissions
* 2 = write permissions
* 4 = read permissions
Example:
// everything for owner, read for owner's group
chmod("test.txt",0740);
6:02 PM
ereg_replace() is used for matching patters to the input string. It then replaces the matched string.
SYNTAX
string ereg_replace ( string $pattern , string $replacement , string $string )
eregi_replace() is used for matching patters to the input string. It then replaces the matched string. The difference is that this function is case sensitive.