Softtek Most Frequently Asked PHP Latest Interview Questions Answers
What Is The Default Session Time In Php And How Can I Change It?
The default session time in php is until closing of browser.
How Many Ways We Can We Find The Current Date Using Mysql?
SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();
When You Want To Show Some Part Of A Text Displayed On An Html Page In Red Font Color? What Different Possibilities Are There To Do This? What Are The Advantages/disadvantages Of These Methods?
There are 2 ways to show some part of a text in red:
1. Using HTML tag <font color="red">
2. Using HTML tag </font>
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 The Default Session Time In Php And How Can I Change It?
The default session time in php is until closing of browser.
How Many Ways We Can We Find The Current Date Using Mysql?
SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();
When You Want To Show Some Part Of A Text Displayed On An Html Page In Red Font Color? What Different Possibilities Are There To Do This? What Are The Advantages/disadvantages Of These Methods?
There are 2 ways to show some part of a text in red:
1. Using HTML tag <font color="red">
2. Using HTML tag </font>
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.
Softtek Most Frequently Asked PHP Latest Interview Questions Answers |
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.
Post a Comment