Google

Saturday, June 7, 2008

how to convert PHP array in to PHP object ?

$a = $array("a"=> 1, "b"=> 2);

now type cast array in to object...


$arrayObj = (object)$a;

now u able to use like object and method.....


echo $arrayObj->a; // output 1
echo $arrayObj->b;// output 2

but only work with key as a string.....not work with indexed array.

How to get current date..in PHP..?????

just simple

use a inbuilt PHP date() function and pass the time() function as a parameter....


like...

echo date("y/m/d",time());

first parameter is date format.

and second is PHP inbuilt time() function.

List of Output Control Functions in PHP 5

o flush — Flush the output buffer
o ob_clean — Clean (erase) the output buffer
o ob_end_clean — Clean (erase) the output buffer and turn off output buffering
o ob_end_flush — Flush (send) the output buffer and turn off output buffering
o ob_flush — Flush (send) the output buffer
o ob_get_clean — Get current buffer contents and delete current output buffer
o ob_get_contents — Return the contents of the output buffer
o ob_get_flush — Flush the output buffer, return it as a string and turn off output

buffering
o ob_get_length — Return the length of the output buffer
o ob_get_level — Return the nesting level of the output buffering mechanism
o ob_get_status — Get status of output buffers
o ob_gzhandler — ob_start callback function to gzip output buffer
o ob_implicit_flush — Turn implicit flush on/off
o ob_list_handlers — List all output handlers in use
o ob_start — Turn on output buffering
o output_add_rewrite_var — Add URL rewriter values
o output_reset_rewrite_vars — Reset URL rewriter values

List of Predefined variables in PHP 5 and PHP 4

PHP5 and PHP4 provides a large number of predefined variables to all scripts.


* Superglobals — Superglobals are built-in variables that are always available in all scopes
* $GLOBALS — References all variables available in global scope
* $_SERVER — Server and execution environment information
* $_GET — HTTP GET variables
* $_POST — HTTP POST variables
* $_FILES — HTTP File Upload variables
* $_REQUEST — HTTP Request variables
* $_SESSION — Session variables
* $_ENV — Environment variables
* $_COOKIE — HTTP Cookies
* $php_errormsg — The previous error message
* $HTTP_RAW_POST_DATA — Raw POST data
* $http_response_header — HTTP response headers
* $argc — The number of arguments passed to script
* $argv — Array of arguments passed to script

PHP5 Encapsulation Surprises to you ..........

In PHP5, unlike Java or C++, $this has to be explicitly used to refer to variables within a

class.

The value of $this is determined by the context in which it is called. In certain situations

$this may actually refer to the invoking class rather then the current class. This breaks object

encapsulation.

$this pseudo-variable is not defined if the method in which it is located is called statically

with an exception as noted below.

$this is defined if a method is called statically from within another object. In this case, the

value of $this is that of the calling object.

The following example from PHP manual will clarify this:

foo();
A::foo();
$b = new B();
$b->bar();
B::bar();
?>

Output:

$this is defined (a)
$this is not defined.
$this is defined (b)
$this is not defined.

Thursday, February 28, 2008

How do I send mails with PHP?

PHP has a function called mail for that purpose, example (from php.net):

mail("nobody@example.com", "the subject", $message,
"From: webmaster@$SERVER_NAME\r\n"
."Reply-To: webmaster@$SERVER_NAME\r\n"
."X-Mailer: PHP/" . phpversion());

For more information about the function look here:
http://www.php.net/manual/en/ref.mail.php

I have lost my MySQL root password, how can I get in?

If you have forgotten the root user password for MySQL, you can restore it with the following procedure:

Take down the mysqld server by sending a kill (not kill -9) to the mysqld server.

The pid is stored in a .pid file, which is normally in the MySQL database directory:
kill `cat /mysql-data-directory/hostname.pid`

You must be either the Unix root user or the same user the server runs as to do this.

Restart mysqld with the --skip-grant-tables option.

Connect to the mysqld server with mysql -h hostname mysql and change the password with a GRANT command.

See section 7.35 GRANT and REVOKE Syntax http://www.mysql.com/doc/G/R/GRANT.html

You can also do this with mysqladmin -h hostname -u user password 'new password'

Load the privilege tables with: mysqladmin -h hostname flush-privileges or with the SQL command FLUSH PRIVILEGES.

Note that after you started mysqld with --skip-grant-tables, any usage of GRANT commands will give you an Unknown command error until you have executed FLUSH PRIVILEGES.