PHP
Archived Posts from this Category
Archived Posts from this Category
I’ve just tried to run PHP with MySQL on my Leopard and the first problem: “Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’”
I’ve just changed php.ini to:
mysql.default_socket = /tmp/mysql.sock
The same situation with mysqli settings - be default it is not set so you should update it to the real path.
And it works!
0 comments Tuesday 08 Jan 2008 | Andrew Dashin | Coding, PHP, MySQL, MacOSX
Here is the function, may somebody will find it usefull.
function ipToNumber($sIp) {
$sPattern = ‘(25[0-5]|2[0-4]\d|[01]?\d\d|\d)’;
if(!preg_match(“/^{$sPattern}\\.{$sPattern}\\.
{$sPattern}\\.{$sPattern}$/”, $sIp)) {
// invalid IP
return -1;
} else {
$aNums = explode(‘.’, $sIp);
$i = count($aNums);
foreach($aNums as $nKey => $nValue) {
$i–;
$nResult += ($aNums[$nKey] * pow(256, $i));
}
return $nResult;
}
}
1 comment Wednesday 13 Dec 2006 | Andrew Dashin | Coding, PHP
Sometimes you need only one instance of your class. For example it can be usefull to create only one instance of your database access class and use it everywhere in application. This will reduce memory usage and prevent you from having more than one database connection.
So, your class should look like bellow:
final class Database
{
private static $instance;
private function __construct()
{
// this code will never happen
}
public static function getInstance()
{
if (!isset(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
public function __clone()
{
trigger_error(‘It is impossible to clone singleton’, E_USER_ERROR);
}
}
This class is defined like final to prevent extentding, usualy people forget about it. It is not a good idea to extend singleton classes because of static members. But if you’ll do this, you also should redefine getInstance() method and $instance member.
3 comments Saturday 25 Nov 2006 | Andrew Dashin | Coding, PHP
while (list(,$vvv) = @each($aTmp)) {
$kkkk = substr($vvv,0,strpos($vvv,‘=’));
$vvvv = substr($vvv,strpos($vvv,‘=’)+1);
$aValues[$kkkk] = $vvvv;
}
This is a part from the code I should work with. No comments.
5 comments Tuesday 14 Nov 2006 | Andrew Dashin | Coding, PHP, WTF
This morning is rich for troubles
Some PHP script was to act with MySQL database, but it failed with: “Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL … Client does not support authentication protocol requested by server; consider upgrading MySQL client“.
I’ve digged a bit and solution was very simple -
SET PASSWORD FOR user@localhost = OLD_PASSWORD(‘newpassword’);
This updates password to use old authentication protocol.
0 comments Tuesday 03 Oct 2006 | Andrew Dashin | Life, Coding, PHP, MySQL
Today I had a problem - on Windows 2000/IIS server PHP didn’t work and scripts were failing with 401.3 error. The solution was very simple - Read/Execute permissions were to be set on PHP directory for IUSR_* and IWAM_* accounts. Since that has been done all works perfect. I
know this is a well known problem, but anyway a lot of people are fighting with it every day.
0 comments Tuesday 03 Oct 2006 | Andrew Dashin | Life, PHP
Yep, at first stage of development I was so busy with logic that absolutely forgot about security. And as result now you can login to alpha Memrefresh version with login “‘ or 1=1 or ‘1′=’1″ and any password. Hurry up I am planning to fix this at monday.
PS and this situation will never happend if I’ve used Java/C# prepared statements.
2 comments Saturday 23 Sep 2006 | Andrew Dashin | Software, Coding, Bugs, My projects, Memrefresh.org, PHP