mysql connect

« Older   Newer »
  Share  
Seth-Ares
CAT_IMG Posted on 26/3/2012, 11:55     +1   -1




ciao e da qualche settimana che non vengo qui sul forum.

ecco il mio problema:
devo connettermi ad un database con l' istruzione mysql_connect().
CODICE
$host = "localhost";
       $user = "root";
       $pass = "123456";
       //Funzione per connetere al database
       function connect(){
               mysql_connect(/*HOST*/'localhost', /*Username*/'root',/*Password*/ 123456') or exit(mysql_error());
       
       }
       function connect_install(){
       
               mysql_connect($host,$user,$pass) or exit(mysql_error());
}

con la funzione connect si connette tranquillamente, con connect_install che utilizzo le variabili non mi connette e mi da questo errore:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\cms\include\config.php on line 21
Access denied for user 'ODBC'@'localhost' (using password: NO)
 
Top
Doch88
CAT_IMG Posted on 26/3/2012, 14:33     +1   -1




Ho googlato un po' ed ho trovato questa risposta alla stessa richiesta su questo forum:

CITAZIONE
Ok, for anyone that is still waiting for an answer on this one. It isn't a php error, it actually isn't even a MySQL error. Essentially what you have done is installed MySQL on a Windows Server, or a Windows operating system. In order to speak to the MySQL installation remotely, you HAVE to let windows know to listen for requests to the MySQL application. In order to do that, you have to add an exception to the windows firewall. If your windows firewall will let you, just open port 3306, if the windows firewall will only allow communications through an application, then you need to locate your MySQL installation directory (usually: C:\Program Files\MySQL\MySQL Server 5.5\bin) but the MySQL Server 5.5 is actually whatever version of MySQL you are running.
Once you locate that folder just find the file mysqld - add that program as the new application for the window firewall to listen through, and then try to connect.

Vedi se ti puņ essere d'aiuto =)
 
Top
KinG-InFeT
CAT_IMG Posted on 21/4/2012, 12:22     +1   -1




la mysql_connect č una sola non due

$conn = mysql_connect ($db_host, $db_user, $db_pass)

e poi

mysql_select_db ($db_name, $conn)

se vuoi puoi usare una classe semplice tipo questa
CODE
<?php

class MySQL {
       private $result = NULL;
       private $conn   = NULL;
       
       public function __construct ($db_host, $db_user, $db_pass, $db_name) {
       
               if (!$this -> conn = @mysql_connect ($db_host, $db_user, $db_pass)) {
                       die ("<div class=\"error\">".mysql_error()."</div>");
               }
               
               if (!@mysql_select_db ($db_name, $this -> conn)) {
                       die ("<div class=\"error\">".mysql_error()."</div>");
               }
       }
       
       public function sendQuery ($query) {
               if (!$this -> result = @mysql_query ($query, $this -> conn)) {
                       die ("<div class=\"error\">SQL Error: ".mysql_error()."</div>");
               }else {
                       return $this -> result;
               }
       }
       
       public function __destruct () {
               @mysql_close ($this -> _conn);
       }
}
?>
 
Top
2 replies since 26/3/2012, 11:55   136 views
  Share