Category Archives: mysql

Manipulate the users of your site with phpUserClass

Standard

Finally I’ve decided to contribute something in the php open source community. Today we’ve published the php user class, which is a class for user manipulation under php and mysql.

The class uses variable settings for database (table, fields), session and cookie variables, and it can easily be used in a new or an established project. I wrote it this way in order to integrate it with other projects that have bad user system and even use it in adition to other open source projects (for instance you can create a stand alone module which will be able to use the users of your wordpress blog 🙂 )

You can see a demonstration of how it works in the examples page.

Hope you will like it 🙂

Advertisements

More php tutorials from webdigity

Standard

I would like to announce that webdigity has opened the tutorials section to non webdigity members, so it would be easier for everyone to get tutorials from them for free.

The webdigity tutorials, consist mostly of php tutorials and there are many code snippets there that you would pay to get them elsewhere.

Also there is an RSS feed for the tutorials which you can subscribe to, if you are interested in coding. Enjoy 🙂

Are you looking for your next web hosting?

Standard

Looking for a web hosting partner is usually a very hard task. This is because there are so many web hosting companies out there, and in most cases you are not able to know how good a company is before you use their services. An example of the problems that may occur is the recent downtime of the online marketing blog which was down for about 18 hours when their hosting provider decided to stop serving them…

Personally I have changed a lot of hosting partners in order to find someone that I can trust. There are many companies that have serious downtimes, others have hidden charges, etc. So when you are looking for web hosting the goal is to find a serious company which is in business for a long time and have no downtime. Of course your web hosting provider should have enough bandwidth to serve your sites fast.

I guess those are the problems that real metrics thought and found a great solution. The solution sounds simple but technically is not. They have bought hosting accounts from several providers, and they run several tests that indicate how good a hosting service is. So in webdigity’s web hosting comparisons you can look for your next web hosting partner with the minimal risk that you could take.

Enjoy 🙂

Backup all your databases with one click

Standard

Bellow is a php script that I made for taking backups of my mySql databases. The script is designed to run under console(CLI) in root mode, so I don’t think that it will work for shared hosting accounts, but you can try it, or try to modify the exec commands with SUDO.

<?php
//================================================
//
// Auto backup your databases
// Author: Nick Papanotas
// Comments/feedback/troubleshooting:
// http://www.webdigity.com/
//
// This script propably wont run from web, except
// if you modify it to add SUDO.
//================================================

$backup_dir = dirname( __FILE__ ) . ‘/backups/’;

$u = ‘User’;
$p = ‘XXXX’;
$db = ‘Adatatbase’;//This is just the name of a database just to make the query work. The script will backup all the databases that your use has access to.

$db_link = mysql_connect($h,$u,$p);
$res = mysql_db_query($db, ‘SHOW DATABASES’, $db_link) or die(‘Could not connect: ‘ . mysql_error());
echo
‘Found ‘. mysql_num_rows($res) . ‘ databases’ . “\n”;

while ( $rec = mysql_fetch_array($res) )
{
//Parse time :
$time = microtime();
$time = explode(‘ ‘, $time);
$time = $time[1] + $time[0];
$start = $time;

echo $rec[0] . “\n”;
shell_exec( ‘mysqldump –result-file=’.$backup_dir.$rec[0].‘.’.date(‘Y-m-d’).‘.sql –password=’.$p.‘ ‘.$rec[0] );
//Parse time :
$time = microtime();
$time = explode(‘ ‘, $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish $start), 6);
echo
‘Parsed in ‘ . $total_time . ‘ secs’ . “\nStarting with compression\n”;
}
//Let’s tar those backups :
shell_exec( ‘tar cvf ‘.$backup_dir.date(‘Y-m-d’).‘.tar ‘.$backup_dir.‘*.sql’ );
?>

This script has been originally posted to webdigity’s code library.

Automatically optimize all tables in a MySQL database

Standard

Use this script preferably with a cronjob to automatically optimize all the tables in your mysql databases. Under root privilleges the script will search for all the databases in your server and will optimize them all. Hope you will like it as it took me more than 3 hours to write it 🙂

 

Optimize all databases/tables in MySQL
For more tutorials you can refer here