Newsgroup: it.comp.www.php
Titolo: mysql connect

mi da il seguente errore:
28000/1045): Access denied for user 'root'@'localhost'
da __phpmyadmin__ funziona con lo stesso user e passord
ho fatto la connessione anche con mysqli stesso problema
e' un mysql su chiavetta usb

 e' un mysql su chiavetta usb
Il messaggio di errore e' piuttosto chiaro.
Se ci sono istanze multiple di MySQL in esecuzione, sei sicuro di
connetterti a quella corretta?
-- 
Vuoi distribuire il tuo sito web su CD/DVD?
Prova 
http://www.dwebpro.com/
Vuoi diventare un esperto analista PHP/MySQL?
Vieni a fare uno stage con noi: 
http://www.creativepark.it/stage/

 
ho verificato, non funziona (il problema lo ho risolto), ci sono 
differenze tra mysqli_connect e mysqli_real_connect
mi pare una cosa assurda un fatto del genere, l'istanza usb gira in 
modalita' riga di comando, l'altra come servizio
i "servizi" li lacio da 1 file php compilato come .exe
se funziona php_myadmin _deve_ funzionare anche il mio

 se funziona php_myadmin deve funzionare anche il mio
Se il tuo non funziona ma phpMyAdmin si non ti viene il dubbio che sia
sbagliato il tuo codice?


 
ho fatto le dovute prove anche con il classico mysql_connect...

 ho fatto le dovute prove anche con il classico mysql_connect...
Potresti postare il codice che non funziona, giusto per curiosita'...


<?php
class sql_db
{
	var $db_connect_id;
	var $query_result;
	var $row = array();
	var $rowset = array();
	var $num_queries = 0;
	var $in_transaction = TRUE;
	//
	// Constructor
	//
	function sql_db($sqlserver, $sqluser, $sqlpassword, $database, 
$persistency = true)
	{
		$this->persistency = $persistency;
		$this->user = $sqluser;
		$this->password = $sqlpassword;
		$this->server = $sqlserver;
		$this->dbname = $database;
		$this->db_connect_id = ($this->persistency) ? 
mysqli_pconnect($this->server, $this->user, $this->password) : 
mysqli_connect($this->server, $this->user, $this->password);
		if( $this->db_connect_id )
		{
			if( $database != "" )
			{
				$this->dbname = $database;
				$dbselect = mysqli_select_db($this->db_connect_id, $this->dbname);
				if( !$dbselect )
				{
					mysqli_close($this->db_connect_id);
					$this->db_connect_id = $dbselect;
				}
			}
			return $this->db_connect_id;
		}
		else
		{
			return false;
		}
	}
	//
	// Other base methods
	//
	function sql_close()
	{
		if( $this->db_connect_id )
		{
			//
			// Commit any remaining transactions
			//
			if( $this->in_transaction )
			{
				mysqli_query($this->db_connect_id, "COMMIT");
			}
			return mysqli_close($this->db_connect_id);
		}
		else
		{
			return false;
		}
	}
	//
	// Base query method
	//
	function sql_query($query = "", $transaction = FALSE)
	{
		//
		// Remove any pre-existing queries
		//
		unset($this->query_result);
		if( $query != "" )
		{
			// echo $query;
       $this->num_queries++;
			if( $transaction == "BEGIN_TRANSACTION" && !$this->in_transaction )
			{
				$result = mysqli_query($this->db_connect_id, "BEGIN");
				if(!$result)
				{
					return false;
				}
				$this->in_transaction = TRUE;
			}
			$this->query_result = mysqli_query($this->db_connect_id, $query);
		}
		else
		{
			if( $transaction == "END_TRANSACTION" && $this->in_transaction )
			{
				$result = mysqli_query($this->db_connect_id, "COMMIT");
			}
		}
      // var_dump($this->query_result);
       // var_dump($this->row);
       // var_dump($this->rowset);
		if( $this->query_result)
		{
 
       $this->row = array();
			$this->rowset= array();
			if( $transaction == "END_TRANSACTION" && $this->in_transaction )
			{
				$this->in_transaction = FALSE;
				if ( !mysqli_query($this->db_connect_id, "COMMIT") )
				{
					mysqli_query($this->db_connect_id, "ROLLBACK");
					return false;
				}
			}
 
			return $this->query_result;
		}
		else
		{
			if( $this->in_transaction )
			{
				mysqli_query($this->db_connect_id, "ROLLBACK");
				$this->in_transaction = FALSE;
			}
			return false;
		}
	}
	//
	// Other query methods
	//
	function sql_numrows($query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		return ( $query_id ) ? mysqli_num_rows($query_id) : false;
	}
	function sql_affectedrows()
	{
		return ( $this->db_connect_id ) ? 
mysqli_affected_rows($this->db_connect_id) : false;
	}
	function sql_numfields($query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		return ( $query_id ) ? mysqli_num_fields($query_id) : false;
	}
	function sql_fieldname($offset, $query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		return ( $query_id ) ? mysqli_field_name($query_id, $offset) : false;
	}
	function sql_fieldtype($offset, $query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		return ( $query_id ) ? mysqli_field_type($query_id, $offset) : false;
	}
	function sql_fetchrow($query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		if( $query_id )
 
		{
 
	//	var_dump( mysqli_fetch_array($query_id, MYSQLI_ASSOC));
 
			return mysqli_fetch_array($query_id, MYSQLI_ASSOC);
			//return $this->row[$query_id];
		}
		else
		{
			return false;
		}
	}
	function sql_fetchrowset($query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		if( $query_id )
		{
			unset($this->rowset["$query_id"]);
			unset($this->row["$query_id"]);
			while($this->rowset["$query_id"] = mysqli_fetch_array($query_id, 
MYSQL_ASSOC))
			{
				$result[] = $this->rowset["$query_id"];
			}
			return $result;
		}
		else
		{
			return false;
		}
	}
	function sql_fetchfield($field, $rownum = -1, $query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		if( $query_id )
		{
			if( $rownum > -1 )
			{
				$result = mysqli_result($query_id, $rownum, $field);
			}
			else
			{
				if( empty($this->row["$query_id"]) && 
empty($this->rowset["$query_id"]) )
				{
					if( $this->sql_fetchrow() )
					{
						$result = $this->row["$query_id"]["$field"];
					}
				}
				else
				{
					if( $this->rowset["$query_id"] )
					{
						$result = $this->rowset["$query_id"][0]["$field"];
					}
					else if( $this->row["$query_id"] )
					{
						$result = $this->row["$query_id"]["$field"];
					}
				}
			}
			return $result;
		}
		else
		{
			return false;
		}
	}
	function sql_rowseek($rownum, $query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		return ( $query_id ) ? mysqlI_data_seek($query_id, $rownum) : false;
	}
	function sql_nextid()
	{
		return ( $this->db_connect_id ) ? 
mysqlI_insert_id($this->db_connect_id) : false;
	}
	function sql_freeresult($query_id = 0)
	{
		if( !$query_id )
		{
			$query_id = $this->query_result;
		}
		if ( $query_id )
		{
			unset($this->row["$query_id"]);
			unset($this->rowset["$query_id"]);
			mysqli_free_result($query_id);
			return true;
		}
		else
		{
			return false;
		}
	}
	function sql_error()
	{
		$result['message'] = mysqli_error($this->db_connect_id);
		$result['code'] = mysqli_errno($this->db_connect_id);
		return $result;
	}
} // class sql_db
?>