TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   The Lounge (http://www.talkphp.com/lounge/)
-   -   PHP Answer Then PHP Question (http://www.talkphp.com/lounge/4746-php-answer-then-php-question.html)

codefreek 07-17-2009 05:05 AM

PHP Answer Then PHP Question
 
Hey, So cecilia made Answer Then ask, so i made this,
PHP Answer Then PHP Question,

Quote:

Example of use:

-Post 1
Q: What is the difference between mysql_connect() and mysql_pconnect()?

--Post 2
Answer :
in short mysql_pconnect() makes a persistent connection to the database which means a SQL link that do not close when the execution of your script ends.

And then your turn to ask a php question.
I made this thread because sometimes, fast answer can save you from the monsters ;)
Enjoy..

PS: Try and keep the question and answer short if possible.

Enfernikus 07-18-2009 02:43 AM

mysqli_connect makes use of the MySQLimproved library which is faster than the old mysql_* function - how ever the OO approached is preferred.

adamdecaf 07-18-2009 05:40 AM

This will be a short/simple answer.

What's the difference between include and require (with standard/default error_reporting).

adamdecaf 07-18-2009 05:05 PM

Quote:

Originally Posted by knight13 (Post 27158)
A: I believe if include(); fails it will produce a warning and if require fails it will produce a fatal error and it will not process the page..Hopefully that is right and what you were asking.

Q: What is the difference between $_GET and $_POST ?

Ya, I wanted the question to be simple..

A: $_GET will retrieve parameters from the URI, it is publicly viewable and editable. $_POST grabs the parameters from the HTTP header (?right?) and it is harder to edit or "hack" but not impossible.

Q: What is the difference from a "for" and a "while" loop?

codefreek 07-18-2009 05:24 PM

A: "For" i mainly to state one action to do, and while is to do while something else is done at the same time if that makes any sense..


Q: How do I find out if an array has values posted to each of its elements? I need to know that EVERY element has been filled out.




PS: I know the answer to this question but to keep the minds flowing i shall ask
questions,

codefreek 07-20-2009 02:22 AM

something like this maybe :)
A:
PHP Code:

$q mysql_query("SELECT LENGTH(firstname) AS thelength FROM myfriends ORDER BY thelength DESC LIMIT 1");
$longestname mysql_result($q,0,0);
echo 
"The longest first name is $longestname letters long!"

Q: How To generate a random number between 0 and 100 ?


srand((double)microtime()*1000000);
echo rand(0,100);

adamdecaf 07-20-2009 02:42 AM

A:
PHP Code:

echo rand(0,100); 



Q: How can you move a file which has been uploaded? (Assume that it is in the $_FILES array).

Village Idiot 07-20-2009 03:31 AM

Quote:

Originally Posted by adamdecaf (Post 27198)
A:
PHP Code:

echo rand(0,100); 

Q: How can you move a file which has been uploaded? (Assume that it is in the $_FILES array).

move_uploaded_file();

Why is MIME type a bad way to validate your uploads?

adamdecaf 07-20-2009 03:35 AM

A: You can hide files in any format you want.

Q: What is a good way to validate file uploads?

Village Idiot 07-20-2009 03:39 AM

Quote:

Originally Posted by adamdecaf (Post 27205)
A: You can hide files in any format you want.

Q: What is a good way to validate file uploads?

Short answer: File extension
Long answer: File extension will suffice, but actually validating the content is the best way (although this is rarely practical).

Which of the following will NOT locally work with PHP on a *nix machine
MySQL
SQL Server 2005
PostgreSQL

codefreek 07-20-2009 04:12 AM

A: SQL Server 2005 (if i remember correctly)


Q: Can you store unlimited data in a cookie ?

adamdecaf 07-20-2009 04:18 AM

A: No, unlimited data does not exist. It is physically impossible to store an infinite amount of data. I think you can store 4 kilobytes.

Q: What is the best way to sort 1,000,000 32-bit integers.

codefreek 07-20-2009 07:12 AM

A:

PHP Code:

function my_function($var1,$var2,$var3){
// Place to enter code here.
$var=$var1+$var2+$var3;
return 
$var;
}
$my_val=my_function(5,6,8);
echo 
"The return value= $my_val";
// The above line will print the sum of the three variables. 

Q: Can anything be stored in a cookie ?

Village Idiot 07-20-2009 06:15 PM

Quote:

Originally Posted by codefreek (Post 27222)
A:

PHP Code:

function my_function($var1,$var2,$var3){
// Place to enter code here.
$var=$var1+$var2+$var3;
return 
$var;
}
$my_val=my_function(5,6,8);
echo 
"The return value= $my_val";
// The above line will print the sum of the three variables. 

Q: Can anything be stored in a cookie ?

No. HTTP limits the cookie header to 4kb.

At what version did PHP add respectable OOP functionality.

codefreek 07-20-2009 07:19 PM

A: PHP4..

Q: How can I create thumbnails using PHP?


All times are GMT. The time now is 06:32 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0