Samsung Electronics Most Frequently Asked Latest PHP Interview Questions Answers
What Is Session_register()?
session_register() is old function that registers global variables into the current session. You should stop using session_register() and use array $_SESSION to save values into the current session now.
What Do You Need To Connect Php To Mysql?
If you want to access MySQL database server in your PHP script, you need to make sure that MySQL module is installed and turned on in your PHP engine. Check the PHP configuration file, php.ini, to make sure the extension=php_mysql.dll is not commented out.
The MySQL module offers a number of functions to allow you to work with MySQL server. Some commonly used MySQL functions are:
• mysql_connect -- Open a connection to a MySQL Server
• mysql_close -- Close MySQL connection
• mysql_db_query -- Send a MySQL query
• mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both
• mysql_free_result -- Free result memory
• mysql_list_tables -- List tables in a MySQL database
• mysql_list_fields -- List MySQL table fields
How To Connect To Mysql From A Php Script?
If you want access the MySQL server, you must create a connection object first by calling the mysql_connect() function in the following format:
$con = mysql_connect($server, $username, $password);
If you are connecting to a local MySQL server, you don't need to specify username and password. If you are connecting to a MySQL server offered by your Web hosting company, they will provide you the server name, username, and password.
The following script shows you how to connect to a local MySQL server, obtained server information, and closed the connection:
<?php
$con = mysql_connect('localhost');
print(mysql_get_server_info($con)."\n");
print(mysql_get_host_info($con)."\n");
mysql_close($con);
?>
How To Run A Sql Statement?
You can run any types of SQL statements through the mysql_query() function. It takes the SQL statement as a string and returns different types of data depending on the SQL statement type and execution status:
• Returning FALSE, if the execution failed.
• Returning a result set object, if the execution is successful on a SELECT statement or other statement returning multiple rows of data.
• Returning TRUE, if the execution is successful on other statements.
Here is a good example of running a SQL statement with the mysql_query() function:
<?php
include "mysql_connection.php";
$sql = 'SELECT sysdate() FROM dual';
$rs = mysql_query($sql, $con);
$row = mysql_fetch_array($rs);
print("Database current time: ". $row[0] ."\n");
mysql_close($con);
?>
How To Get The Number Of Rows Selected Or Affected By A Sql Statement?
There are two functions you can use the get the number of rows selected or affected by a SQL statement:
mysql_num_rows($rs) - Returns the number of rows selected in a result set object returned from SELECT statement.
mysql_affected_rows() - Returns the number of rows affected by the last INSERT, UPDATE or DELETE statement.
What Is A Result Set Object?
A result set object is a logical representation of data rows returned by mysql_query() function on SELECT statements. Every result set object has an internal pointer used to identify the current row in the result set. Once you get a result set object, you can use the following functions to retrieve detail information:
• mysql_free_result($rs) - Closes this result set object.
• mysql_num_rows($rs) - Returns the number rows in the result set.
• mysql_num_fields($rs) - Returns the number fields in the result set.
• mysql_fetch_row($rs) - Returns an array contains the current row indexed by field position numbers.
• mysql_fetch_assoc($rs) - Returns an array contains the current row indexed by field names.
• mysql_fetch_array($rs) - Returns an array contains the current row with double indexes: field position numbers and filed names.
• mysql_fetch_lengths($rs) - Returns an array contains lengths of all fields in the last row returned.
• mysql_field_name($rs, $i) - Returns the name of the field of the specified index.
What Is File Upload?
File upload is Web page function which allows visitor to specify a file on the browser's system and submit it to the Web server. This is a very useful function for many interactive Web sites. Some examples are:
Web base email systems for users to send attachments.
Forums that allows user to submit pictures.
Web sites file managers for users to build their own Web pages.
Which HTML Tag Allows Users to Specify a File for Uploading?
To present an input field on your Web page to allow users to specify a local file to upload, you need to use the <INPUT TYPE="FILE" ...> tag inside a <FORM ...> tag. The <INPUT TYPE="FILE" ...> will be displayed as a text input field followed by a button called "Browse...". Users can either enter the full path name of a local file, or click Browse button to go through a dialog box to select a file interactively. The following PHP code shows you a good example of the file upload tag:
<?php
print("<html><form>n");
print("<input type=file>n");
print("<input type=submit>n");
print("</form></html>n");
?>
What Is The Difference Between Char And Varchar Data Types?
CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.
VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.
How Can We Encrypt And Decrypt A Data Present In A Mysql Table Using Mysql?
AES_ENCRYPT() and AES_DECRYPT().
How Can We Change The Name Of A Column Of A Table?
MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name
or,
ALTER TABLE tableName CHANGE OldName newName.
How Can Increase The Performance Of Mysql Select Query?
We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.
Will Comparison Of String "10" And Integer 11 Work In Php?
Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.
What Type Of Inheritance That Php Supports?
In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'.
What Is The Functionality Of Md5 Function In Php?
string md5(string)
It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.
How Can I Load Data From A Text File Into A Table?
The MySQL provides a LOAD DATA INFILE command. You can load data from a file.
Great tool but you need to make sure that:
a) Data must be delimited.
b) Data fields must match table columns correctly.
How Can We Know The Number Of Days Between Two Given Dates Using Mysql?
Use DATEDIFF()
SELECT DATEDIFF(NOW(),'2006-07-01');
How Can We Change The Data Type Of A Column Of A Table?
This will change the data type of a column:
ALTER TABLE table_name CHANGE colm_name same_colm_name [new data type].
How Can We Know That A Session Is Started Or Not?
A session starts by session_start() function.
This session_start() is always declared in header portion. it always declares first. then we write session_ register().
How Many Ways We Can Give The Output To A Browser?
HTML output
PHP, ASP, JSP, Servlet Function
Script Language output Function
Different Type of embedded Package to output to a browser.
Please Give A Regular Expression (preferably Perl/preg Style), Which Can Be Used To Identify The Url From Within A Html Link Tag?
Try this: /href="([^"]*)"/i.
Give The Syntax Of Grant Commands?
The generic syntax for GRANT is as following
GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]
Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.
What Are The Different Ways To Login To A Remote Server? Explain The Means, Advantages And Disadvantages?
There is at least 3 ways to logon to a remote server:
Use ssh or telnet if you concern with security
You can also use rlogin to logon to a remote server.
Give The Syntax Of Revoke Commands?
The generic syntax for revoke is as following
REVOKE [rights] on [database] FROM [username@hostname]
Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.
What Is Session_register()?
session_register() is old function that registers global variables into the current session. You should stop using session_register() and use array $_SESSION to save values into the current session now.
What Do You Need To Connect Php To Mysql?
If you want to access MySQL database server in your PHP script, you need to make sure that MySQL module is installed and turned on in your PHP engine. Check the PHP configuration file, php.ini, to make sure the extension=php_mysql.dll is not commented out.
The MySQL module offers a number of functions to allow you to work with MySQL server. Some commonly used MySQL functions are:
• mysql_connect -- Open a connection to a MySQL Server
• mysql_close -- Close MySQL connection
• mysql_db_query -- Send a MySQL query
• mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both
• mysql_free_result -- Free result memory
• mysql_list_tables -- List tables in a MySQL database
• mysql_list_fields -- List MySQL table fields
How To Connect To Mysql From A Php Script?
If you want access the MySQL server, you must create a connection object first by calling the mysql_connect() function in the following format:
$con = mysql_connect($server, $username, $password);
If you are connecting to a local MySQL server, you don't need to specify username and password. If you are connecting to a MySQL server offered by your Web hosting company, they will provide you the server name, username, and password.
The following script shows you how to connect to a local MySQL server, obtained server information, and closed the connection:
<?php
$con = mysql_connect('localhost');
print(mysql_get_server_info($con)."\n");
print(mysql_get_host_info($con)."\n");
mysql_close($con);
?>
How To Run A Sql Statement?
You can run any types of SQL statements through the mysql_query() function. It takes the SQL statement as a string and returns different types of data depending on the SQL statement type and execution status:
• Returning FALSE, if the execution failed.
• Returning a result set object, if the execution is successful on a SELECT statement or other statement returning multiple rows of data.
• Returning TRUE, if the execution is successful on other statements.
Here is a good example of running a SQL statement with the mysql_query() function:
<?php
include "mysql_connection.php";
$sql = 'SELECT sysdate() FROM dual';
$rs = mysql_query($sql, $con);
$row = mysql_fetch_array($rs);
print("Database current time: ". $row[0] ."\n");
mysql_close($con);
?>
How To Get The Number Of Rows Selected Or Affected By A Sql Statement?
There are two functions you can use the get the number of rows selected or affected by a SQL statement:
mysql_num_rows($rs) - Returns the number of rows selected in a result set object returned from SELECT statement.
mysql_affected_rows() - Returns the number of rows affected by the last INSERT, UPDATE or DELETE statement.
Samsung Electronics Most Frequently Asked Latest PHP Interview Questions Answers |
What Is A Result Set Object?
A result set object is a logical representation of data rows returned by mysql_query() function on SELECT statements. Every result set object has an internal pointer used to identify the current row in the result set. Once you get a result set object, you can use the following functions to retrieve detail information:
• mysql_free_result($rs) - Closes this result set object.
• mysql_num_rows($rs) - Returns the number rows in the result set.
• mysql_num_fields($rs) - Returns the number fields in the result set.
• mysql_fetch_row($rs) - Returns an array contains the current row indexed by field position numbers.
• mysql_fetch_assoc($rs) - Returns an array contains the current row indexed by field names.
• mysql_fetch_array($rs) - Returns an array contains the current row with double indexes: field position numbers and filed names.
• mysql_fetch_lengths($rs) - Returns an array contains lengths of all fields in the last row returned.
• mysql_field_name($rs, $i) - Returns the name of the field of the specified index.
What Is File Upload?
File upload is Web page function which allows visitor to specify a file on the browser's system and submit it to the Web server. This is a very useful function for many interactive Web sites. Some examples are:
Web base email systems for users to send attachments.
Forums that allows user to submit pictures.
Web sites file managers for users to build their own Web pages.
Which HTML Tag Allows Users to Specify a File for Uploading?
To present an input field on your Web page to allow users to specify a local file to upload, you need to use the <INPUT TYPE="FILE" ...> tag inside a <FORM ...> tag. The <INPUT TYPE="FILE" ...> will be displayed as a text input field followed by a button called "Browse...". Users can either enter the full path name of a local file, or click Browse button to go through a dialog box to select a file interactively. The following PHP code shows you a good example of the file upload tag:
<?php
print("<html><form>n");
print("<input type=file>n");
print("<input type=submit>n");
print("</form></html>n");
?>
What Is The Difference Between Char And Varchar Data Types?
CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.
VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.
How Can We Encrypt And Decrypt A Data Present In A Mysql Table Using Mysql?
AES_ENCRYPT() and AES_DECRYPT().
How Can We Change The Name Of A Column Of A Table?
MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name
or,
ALTER TABLE tableName CHANGE OldName newName.
How Can Increase The Performance Of Mysql Select Query?
We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.
Will Comparison Of String "10" And Integer 11 Work In Php?
Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.
What Type Of Inheritance That Php Supports?
In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'.
What Is The Functionality Of Md5 Function In Php?
string md5(string)
It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.
How Can I Load Data From A Text File Into A Table?
The MySQL provides a LOAD DATA INFILE command. You can load data from a file.
Great tool but you need to make sure that:
a) Data must be delimited.
b) Data fields must match table columns correctly.
How Can We Know The Number Of Days Between Two Given Dates Using Mysql?
Use DATEDIFF()
SELECT DATEDIFF(NOW(),'2006-07-01');
How Can We Change The Data Type Of A Column Of A Table?
This will change the data type of a column:
ALTER TABLE table_name CHANGE colm_name same_colm_name [new data type].
How Can We Know That A Session Is Started Or Not?
A session starts by session_start() function.
This session_start() is always declared in header portion. it always declares first. then we write session_ register().
How Many Ways We Can Give The Output To A Browser?
HTML output
PHP, ASP, JSP, Servlet Function
Script Language output Function
Different Type of embedded Package to output to a browser.
Please Give A Regular Expression (preferably Perl/preg Style), Which Can Be Used To Identify The Url From Within A Html Link Tag?
Try this: /href="([^"]*)"/i.
Give The Syntax Of Grant Commands?
The generic syntax for GRANT is as following
GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]
Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.
What Are The Different Ways To Login To A Remote Server? Explain The Means, Advantages And Disadvantages?
There is at least 3 ways to logon to a remote server:
Use ssh or telnet if you concern with security
You can also use rlogin to logon to a remote server.
Give The Syntax Of Revoke Commands?
The generic syntax for revoke is as following
REVOKE [rights] on [database] FROM [username@hostname]
Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.
Post a Comment