FabioRicali.it

Connessione a mysql con php

by info@fabioricali.it on mag.08, 2010, under PHP

Qui di seguito vi mostro una classe utile per connettervi al vostro database mysql

<?php
    class Connection{
    	public $host;
    	public $user;
    	public $password;
    	public $db;
    	private $conn;
 
       public function connect() {
    		// connessione
    		$this->conn = mysql_connect($this->host, $this->user, $this->password);
    		mysql_select_db($this->db,$this->conn)or die(mysql_error());
    		mysql_query("SET NAMES UTF8");
       }
 
       function __destruct() {
           mysql_close($this->conn);
       }    
 
    }
 
    //Creo l'oggetto
    $connection = new Connection();
 
   	//Setto i parametri
    $connection->host = "your_host";
    $connection->user = "your_user";
    $connection->password = "your_password";
    $connection->db = "your_db";
 
    //Mi connetto
    $connection->connect();
?>
Leave a Comment : more...

Validare un indirizzo email con php

by info@fabioricali.it on mag.08, 2010, under PHP

Un modo semplice e volce per validare un indirizzo email tramite php รจ rappresentato dalla funzione (da PHP 5) filter_var
ecco un esempio:

<?php  
if(!filter_var("email@email.com", FILTER_VALIDATE_EMAIL)){
	echo("E-mail non corretta");
}else{
	echo("E-mail corretta");
}
?>

In caso di successo ritorna il valore, altrimenti FALSE.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...