Been working on a web app, have a core class with 2 database connections $connection and $connectionProgramme each connect to different database with same user and password
All works fine throughout system but on one of the classes (which extends the core class), when I pass the db connecction in the mysql_query, it fails and when I leave it out it works fine. I pass the second parameter throughout the rest of the functions in the class and other classes and it’s fine, just this one.
Jus trying to work out why? If anyone has ideas be great to hear them. Have included code below:
Connection function in core class:
{start of snippet}
// CONNECT TO DATABASE
private function connect() {
#deal with system database connection
$conn = mysql_connect($this->host, $this->username, $this->password);
if($conn == false)
$this->error = "Unable to connect to database server: ".mysql_error();
if(!mysql_select_db($this->database, $conn))
$this->error = "Unable to select system database: ".mysql_error();
$this->connection = $conn;
#deal with programme database connection
$connProgramme = mysql_connect($this->host, $this->username, $this->password, true);
if($connProgramme == false)
$this->error = "Unable to connect to database server: ".mysql_error();
if(!mysql_select_db($this->databaseProgramme, $connProgramme)) {
$this->error = "Unable to select programme database: ".mysql_error();
}
$this->connectionProgramme = $connProgramme;
}
{end core snippet}
The other class extends this one. Has a function with the snippet below:
{snippet start}
$sqlProgramme = "SELECT _programme.* ".
"FROM _programme, person ".
"WHERE _programme.personID=person.personID ".
“ORDER BY firstName, lastName”;
$resProgramme = mysql_query($sqlProgramme, $this->connectionProgramme) or die("issue is ".mysql_error());
{snippet end}
If I take out $this->connectionProgramme in the mysql_query function the query works fine. If I leave it in it fails but NO mysql_error() is generated.
I’m sure it’s something simple or stupid I’m doing but can’t work this one out. Any suggestions greatly appreciated.
Thanks