Tag Archives: PHP

Php Interview Questions and Answers – Part 9

images




1- 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(). 2- What are the differences between  mysql_fetch_array(),  mysql_fetch_object(),  mysql_fetch_row()? Answer 1: mysql_fetch_array() -> Fetch a result row as a combination of associative array and regular array. mysql_fetch_object() -> Fetch a result row as an object. mysql_fetch_row() -> Fetch a result set as a regular array(). Answer […]

Select Records using PHP MySQL Select Statement

online tutorilas




You can use SELECT statement to select data from a database. Syntax SELECT column_name(s) FROM table_name To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection. For Example: The following example selects all the data stored in the “student” table (The * character selects all the data in the table): <?php $con = mysql_connect(“localhost”,”username”,”password”); if (!$con) { die(‘Could not connect: ‘ . […]

Create a CSV file using PHP and MYSQL

csv




As we know that CSV files are one of the most used way to back-up mysql database and tables. However it is very simple to export or backup your mysql database table as CSV file if you have PhpMyAdmin interface installed on your server. Actually problem arises when we have to deal with a shared hosting. But by using PHP script, you can export complete mysql database table to csv files. Here in this post I have given you a […]

Swapping Array Keys and Values

Swapping Array




In this article we discuss about Swapping Array Keys and Values. If you want interchange the keys and values of an associative array. It’s very easy, just use PHP’s array_flip() function which perform a very specialized task. It reverses the key-value relationship for all the elements of an associative array and returning a new array that is the mirror image of the original. <?php $opposite_key_value = array(“white” => “black”, “day” => “night”, “open” => “close”); print_r(array_flip($opposite_key_value)); ?>

Php Interview Questions and Answers – Part 8

Php Interview Questions and Answers




Php Interview Questions and Answers – Part 8 1- 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 privileges b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc. We can grant rights on all database by using *.* or some specific database by database.* or a specific table by database.table_name. 2- What is the difference between CHAR and VARCHAR data types? […]

Sorting using MySQL ORDER BY Statement

Sorting using PHP MySQL ORDER BY Statement




We use Sorting using MySQL  Order by statement in a recordset.The ORDER BY keyword sort the records in ascending order by default. If you want to sort the records in a descending order, you can use the DESC keyword. SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC You can sort on multiple columns, and you can sort different columns in different directions This query would return me the results ordered by the species in the order I need and then sort […]

Php Interview Questions and Answers – Part 7

images




This is the 7th part of Php Interview Questions and Answers. 1- How can we destroy the session, how can we unset the variable of a session? session_unregister() – Unregister a global variable from the current session session_unset() – Free all session variables 2- What are the different functions in sorting an array? Sorting functions in PHP: asort() arsort() ksort() krsort() uksort() sort() natsort() rsort() 3- How can we know the count/number of elements of an array? 2 ways: a) sizeof($array) […]

Convert .xsd file into array in PHP

jpeg




As we know that PHP has no direct function to convert .xsd(XML Schema Definition) file into associative array like XML file. So you have to  first convert .xsd file into xml then finally parse xml file into associative array. Below are few easy steps to convert .xsd file into associative array.   $doc->preserveWhiteSpace = true; $doc->load(‘yourfile.xsd’); Step 2: Save .xsd file as an xml file. $doc->save(‘myxml.xml’); Step 3: Generate xml as a string and removed xsd prefixes. $myxmlfile = file_get_contents(‘myxml.xml’); […]

Php Interview Questions and Answers – Part 6

php-interview-title




1- How can we register the variables into a session? session_register($session_var); $_SESSION[‘var’] = ‘value’; 2- What is the difference between characters �23 and x23? The first one is octal 23, the second is hex 23. With a heredoc syntax, do I get variable substitution inside the heredoc contents? Yes. 3- How can we submit form without a submit button? We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we […]

Php Interview Questions and Answers – Part 5

php3




1- How to reset/destroy a cookie ? Reset a cookie by specifying expire time in the past: Example: setcookie(‘Test’,$i,time()-3600); // already expired time Reset a cookie by specifying its name only Example: setcookie(‘Test’); 2- What types of images that PHP supports ? Using imagetypes() function to find out what types of images are supported in your PHP engine. imagetypes() – Returns the image types supported. This function returns a bit-field corresponding to the image formats supported by the version of […]