Database Conflict

Hey everyone. I've got a database where I store some info that I call on every page's header. It's a band most recent show. However, when including my SQL connect, something's conflicting and ZenPhoto begins looking in the show's database instead of it's own.

I've included the offending code at the bottom. Am I using a shared function or something?

`

<?php</p>

// Make the connnection and then select the database.

$dbc = @mysql_connect ('localhost', 'hilcrest_shows', 'shows') OR die ('Could not connect to MySQL: ' . mysql_error() );

mysql_select_db ('hilcrest_shows', $dbc) OR die ('Could not select the database: ' . mysql_error() );

function escape_data ($data) {

global $dbc; // Need the connection.

if (ini_get('magic_quotes_gpc')) {

$data = stripslashes($data);

}

return mysql_real_escape_string($data, $dbc);

} // End of function.

?>

`

Comments

  • trisweb Administrator
    The PHP manual says this of mysql_select_db:

    "Sets the current active database on the server that's associated with the specified link identifier. Every subsequent call to mysql_query() will be made on the active database."

    Zenphoto's query() functions don't use the second argument to mysql_query, so it uses the latest connection from mysql_select_db to run the query, which is wrong.

    It's now fixed in SVN and will be in the next release. Until then edit line 25 of `functions-db.php` from:
    `$result = mysql_query($sql) or die(....);`
    to
    `$result = mysql_query($sql, $mysql_connection) or die(....);`

    Sorry for not using the connection, that's my bug. :)
  • Ah, perfect. Worked like a charm. Good to see this will be in future releases. Thanks for the perfect support!
  • trisweb Administrator
    My pleasure :) Thanks for using Zenphoto.
Sign In or Register to comment.