Page 1 of 1

ODBC@localhost errors

Posted: Mon Sep 17, 2007 4:42 am
by diditin
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, i am actually a beginner in php, and trying to work with design patterns.

I installed wamp server.
here are my codes:

factoryConnectionTest.php

Code: Select all

<?php

class factoryConnectionTest
{
   function factory($dblogin, $dbpass, $dbname, $dbhost)
    {
               include_once 'connexion.php' ;
        	   return new Connexion($dbhost, $dblogin, $dbpass, $dbname) ;
     }

}

?>

connexion.php

Code: Select all

<?php

class Connexion
{

	private $host;
	private $user;
	private $pass;
	private $base;
	
	public function _construct($hos, $use, $pas, $bas)
	{
		$this->host = $hos; 
    	$this->user = $use; 
    	$this->pass = $pas;
    	$this->base = $bas;
		connect($this->host, $this->user, $this->pass, $this->base);
	}
	
	public function connect($hos, $use , $pas , $bas)
	{
		mysql_connect('$hos','$use','$pas');
	}
	
}

?>
ExSQLConnection.php

Code: Select all

<?php

include_once "factoryConnectionTest.php" ;
$dblogin = 'root' ;
$dbpassword = '' ;
$dbdatabase = 'test' ;
$dbhost = 'localhost';

$db = factoryConnectionTest::factory($dblogin, $dbpassword, $dbdatabase, $dbhost);
[b]
$reponse = mysql_query("SELECT * FROM jeux_videos"); // RequĂȘte SQL[/b]

while ($donnees = mysql_fetch_array($reponse) )
{
echo $donnees[''];
echo $donnees['possesseur'];
echo $donnees['id']; 
}
mysql_close(); // Déconnexion de MySQL
?>
when opening the ExSQLConnection.php on a browser, it gives me the following errors:

Code: Select all

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\FichTelePhp\ExSQLConnection.php on line 12

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\FichTelePhp\ExSQLConnection.php on line 12
Access denied for user 'ODBC'@'localhost' (using password: NO)

I tried my best, but can't fgure out what is wrong. Thanks in advance for your help...
++
dave


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Sep 17, 2007 5:56 am
by volka
Variable substitution only takes place within double-quoted strings

Code: Select all

$x = 123;
echo "# $x # ";
echo '# $x # ';
prints
# 123 ## $x #
Therefore
diditin wrote:mysql_connect('$hos','$use','$pas');
passes the strings $hos, $use and $pas to the function mysql_connect, not the values of the variables. Since your classes lack error handling this error hasn't been propagated.

If you're new not only to php but also object oriented programming and database handling in general I suggest not to rush things by writing your own database handling classes but to use an existing database layer/abstraction/... like e.g. pdo

ODBC@localhost error solved...but another problem arises

Posted: Tue Sep 18, 2007 10:21 am
by diditin
hi, i wrote new classes for connexion:

Connexion.php

Code: Select all

<?php
class Connexion
{

	private $dblogin;
	private $dbpass;
	private $dbhost;
	private $dbname;
	
	
	public function _construct($dbl, $dbp, $dbh, $dbn)
	{
		$this->dblogin = $dbl;
		$this->dbpass = $dbp;
		$this->dbhost = $dbh;
		$this->dbname = $dbn;
		return mysql_pconnect($dbhost, $dblogin, $dbpass);
	}
}


?>
factoryClasses.php

Code: Select all

<?php

class factoryClasses
{

public function factoryConnexion($dblogin, $dbpass, $dbhost)
{
	include_once("Connexion.php");
	return new Connexion($dblogin, $dbpass, $dbhost);
}

public function getDatabase($dbname, $link)
{
	echo "dataB called:";echo $dbname;
	return mysql_select_db($dbname,$link);
}
}

?>
RunConnexionFactoryClasses.php

Code: Select all

<?php
echo "1";
include_once("factoryClasses.php");
echo "2";
$connec = factoryClasses::factoryConnexion('root', '','localhost');
echo "3";
if (!$connec)
{ echo "impossible de se connecter";}
else
{ echo "connection etablie";}
include_once("factoryClasses.php");
$getDb= factoryClasses::getDatabase("information_schema", $connec);
if (!$getDb)
{ echo "database not succeeded";}
else
{ echo "database succeeded";}

?>
After running the RunConnexionFactoryClasses, there is no more the ODBC@localhost error, but another problem arises with mysql request.

Thanx in advance for your help!

cheers
dave