Saturday, March 27, 2010

New Interview Questions

1. how to get the ip address.
2. diff. b/w echo,print, print_r.
3. ftp php (how we connect to ftp)(ans: ftp_connect() "Opens an FTP connection")
4. paypal
5. php oops
6. pconnect, connect
7. Explain join queries
8. Example of Join Query(join,left,right)
9. step of joomla template
10. function overriding and overloading.
11. array merge ans: $ab=array_merge(array('a','b'),array('c','d'));
12. find max salary and min salary using join.


mysql_pconnect() acts very much like mysql_connect() with two major differences.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).

This type of link is therefore called 'persistent'.

Uploading files

CREATE TABLE my_files (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(75) NOT NULL,
type VARCHAR(255) NOT NULL,
size INT(11) NOT NULL,
data MEDIUMBLOB NOT NULL,
created DATETIME,
modified DATETIME,
PRIMARY KEY (id)
);


// app/models/my_file.php
class MyFile extends AppModel {
var $name = 'MyFile';
}


// app/views/my_files/add.ctp (Cake 1.2)
echo $form->create('MyFile', array('action' => 'add', 'type' => 'file'));
echo $form->file('File');
echo $form->submit('Upload');
echo $form->end();
?>

// app/views/my_files/add.thtml (Cake 1.1)

file('File'); ?>
submit('Upload'); ?>



// app/controllers/my_files_controller.php (Cake 1.2)
class MyFilesController extends AppController {
function add() {
if (!empty($this->data) &&
is_uploaded_file($this->data['MyFile']['File']['tmp_name'])) {
$fileData = fread(fopen($this->data['MyFile']['File']['tmp_name'], "r"),
$this->data['MyFile']['File']['size']);

$this->data['MyFile']['name'] = $this->data['MyFile']['File']['name'];
$this->data['MyFile']['type'] = $this->data['MyFile']['File']['type'];
$this->data['MyFile']['size'] = $this->data['MyFile']['File']['size'];
$this->data['MyFile']['data'] = $fileData;

$this->MyFile->save($this->data);

$this->redirect('somecontroller/someaction');
}
}
}

// app/controllers/my_files_controller.php (Cake 1.1)
class MyFilesController extends AppController {
function add() {
if (!empty($this->params['form']) &&
is_uploaded_file($this->params['form']['File']['tmp_name'])) {
$fileData = fread(fopen($this->params['form']['File']['tmp_name'], "r"),
$this->params['form']['File']['size']);
$this->params['form']['File']['data'] = $fileData;

$this->MyFile->save($this->params['form']['File']);

$this->redirect('somecontroller/someaction');
}
}
}



and for download that file:

function download($id) {
Configure::write('debug', 0);
$file = $this->MyFile->findById($id);

header('Content-type: ' . $file['MyFile']['type']);
header('Content-length: ' . $file['MyFile']['size']);
header('Content-Disposition: attachment; filename="'.$file['MyFile']['name'].'"');
echo $file['MyFile']['data'];

exit();
}

how to redirect automatically Using meta tag

"start head tag here"
less than META HTTP-EQUIV="Refresh" CONTENT="10;URL=http://www.example.org/articles.htm">
"end head tag here"


parvinder kumar is online.
parvinder:

BODY onLoad="redirect()">

How to bake a cake application

E:\cake_test\app>..\cake\console\cake bake