PHP

  Home  Computer Programming  PHP


“Learn PHP programming with Interview Questions and Answers and examples.”



139 PHP Questions And Answers

121⟩ What is maximum size of a database in mysql?

If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint. The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected.

The amount of available disk space limits the number of tables.

MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits.

The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB.

 159 views

123⟩ Explain normalization concept?

The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed).

First Normal Form

The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of data in a given row, and that every column stores the least amount of information possible (making the field atomic).

Second Normal Form

Where the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form.

Third Normal Form

I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependent on the primary key, but defendant on another value in the table

 135 views

124⟩ How can I use the COM components in php?

The COM class provides a framework to integrate (D)COM components into your PHP scripts.

string COM::COM( string module_name [, string server_name [, int codepage]]) - COM class constructor.

Parameters:

module_name: name or class-id of the requested component.

server_name: name of the DCOM server from which the component should be fetched. If NULL, localhost is assumed. To allow DCOM com, allow_dcom has to be set to TRUE in php.ini.

codepage - specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 and CP_UTF8.

Usage:

$word->Visible = 1; //open an empty document

$word->Documents->Add(); //do some weird stuff

$word->Selection->TypeText("This is a test…");

$word->Documents[1]->SaveAs("Useless test.doc"); //closing word

$word->Quit(); //free the object

$word->Release();

$word = null;

 159 views

128⟩ What changes I have to do in php.ini file for file uploading?

Make the following line uncomment like:

; Whether to allow HTTP file uploads.

file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not

; specified).

upload_tmp_dir = C:apache2triadtemp

; Maximum allowed size for uploaded files.

upload_max_filesize = 2M

 152 views

130⟩ Explain about Type Juggling in php?

PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable $var, $var becomes a string. If you then assign an integer value to $var, it becomes an integer.

An example of PHP's automatic type conversion is the addition operator '+'. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.

$foo += 2; // $foo is now an integer (2)

$foo = $foo + 1.3; // $foo is now a float (3.3)

$foo = 5 + "10 Little Piggies"; // $foo is integer (15)

$foo = 5 + "10 Small Pigs"; // $foo is integer (15)

If the last two examples above seem odd, see String conversion to numbers.

If you wish to change the type of a variable, see settype().

If you would like to test any of the examples in this section, you can use the var_dump() function.

Note: The behavior of an automatic conversion to array is currently undefined.

Since PHP (for historical reasons) supports indexing into strings via offsets using the same syntax as array indexing, the example above leads to a problem: should $a become an array with its first element being "f", or should "f" become the first character of

 152 views

132⟩ How To Turn On the Session Support in PHP?

The session support can be turned on automatically at the site level, or manually in each PHP page script:

* Turning on session support automatically at the site level: Set session.auto_start = 1 in php.ini.

* Turning on session support manually in each page script: Call session_start() funtion.

 166 views

133⟩ How can I embed a java program in php file and what changes have to be done in php.ini file?

There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.

The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.

Example Code:

getProperty('java.version') . ''; echo 'Java vendor=' . $system->getProperty('java.vendor') . ''; echo 'OS=' . $system->getProperty('os.name') . ' ' . $system->getProperty('os.version') . ' on ' . $system->getProperty('os.arch') . ' '; // java.util.Date example $formatter = new Java('java.text.SimpleDateFormat', "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz"); echo $formatter->format(new Java('java.util.Date')); ?>

The behavior of these functions is affected by settings in php.ini.

Table 1. Java configuration options

Name

Default

Changeable

java.class.path

NULL

PHP_INI_ALL

Name Default Changeable

java.home

NULL

PHP_INI_ALL

java.library.path

NULL

PHP_INI_ALL

java.library

JAVALIB

PHP_INI_ALL

 213 views

134⟩ What is the difference between include and require?

It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

 180 views

137⟩ How To Read the Entire File into a Single String?

If you have a file, and you want to read the entire file into a single string, you can use the file_get_contents() function. It opens the specified file, reads all characters in the file, and returns them in a single string. Here is a PHP script example on how to file_get_contents():

<?php

$file = file_get_contents("/windows/system32/drivers/etc/services");

print("Size of the file: ".strlen($file)."n");

?>

This script will print:

Size of the file: 7116

 162 views