2006/11/21

Solution for 'php connect to mysql problem'

Q: I keep getting an Error connecting to database message but I'm sure my configuration is correct.
A: Try resetting your MySQL password manually. If you have access to MySQL via shell, try issuing:

SET PASSWORD FOR 'wordpressusername'@'hostname' = OLD_PASSWORD('password');

note: If you are using a version of MySQL prior to 4.1, use PASSWORD instead of OLD_PASSWORD. If you do not have shell access, you should be able to simply enter the above into an SQL query in phpMyAdmin. Failing that, you may need to use your host's control panel to reset the password for your database user.

2006/11/16

exit, return, die

exit: terminate the program, it will return 0
exit(1): terminate the program, return 256;
exit(2): terminate the program, return 512;

die: terminate the program, return 65280;

return: return from a function, and it cannot be used outside function.

Note: If the program use multithreading and one thread died, then the whole program will not end until all other threads end.

2006/11/15

Spawning other program in perl

1. Backtick:
`system call or other program `;
No standard output of system call/other program can be shown on the current standard output, but standard error will be shown.
You can use a variable to hold the standard output, and then print it out. For example:
$stand_out = `system call or other program`, print “$stand_out”;

2. System ( )
system (“system call/other program”)
Both standard output and standard error of system call/other program will be shown on the current standard output.
If you use:
$result = system (“system call/other program”)
You will get $result = 0, when there is no error in system call/other program, otherwise, you will get strange number like 256/-1.

2006/11/14

Delete multiple files in Perl

Just found a way to delete useless files in a current directory.


foreach $file (<*.tmp>) { # step through a list of .tmp files
unlink($file) || warn "having trouble deleting $file: $!";
}


reference

Soap

SOAP (Simple Object Access Protocol) is a way to make function calls upon classes and objects, which exist on a remote server.

2006/11/10

Using return + Multithread

There is a 'join' function in Perl when using threads module.


use threads;
use threads::shared;

my @t;
for my $i (1..$num)
{
push @t, threads->new(\&ajxss_wt, $i, $name[$i]);
}
for (@t) { $_->join;}

print "something";


Without 'join' here, "something" will be print immediately, but with 'join', print function will hold until every thread ends.

How to know if thread ends? It will check the return value from 'ajxss_wt' function.
So return 1 must have at the end of 'ajxss_wt' function.

As I found, it is better to make ajxss_wt simple.

Note: For a large number of threads, this code does not work well in cgi-bin. But we can embed this piece of code into system call.

Update: Just found firefox may not be able to support multithread in my case, but IE works fine.

2006/11/06

Some UNIX commands

Create a symbolic link:

ln -s phpMyAdmin-2.9.0.3-all-languages phpmyadmin


Change MySql user's PASSWORD:

mysql> SET PASSWORD FOR
    -> some_user@some_host = OLD_PASSWORD('newpwd');