Jason wrote:
Rick Fletcher wrote:

function db( $host, $user, $pass, $dbnam ) {
$db = @mysql_pconnect( $host, $user, $pass )or die( mysql_error( $db ));
@mysql_select_db( $dbnam )or die( mysql_error( $db ) );
return $db;
}


function logs() {
 global $defined;

 db( $defined[9], $defined[1], $defined[2], $defined[3] );
 ... do some processing ...

}

what am i missing here? i get errors if i try to pass $db to logs. i.e. logs( $db );



What's missing? The error message. Include it, and the offending line(s) of code, and ask again.


--Rick

There isnt an error at all. According to the die() functions at the end of the mysql() functions it should give it there, instead I get blank as if the function has not successfully completed. The reason I say this is if you try to access the mysql resource pointer ( $db, in this case ) I get nothing, a return code of 0. Example in point...


function db( $host, $user, $pass, $dbnam ) {
$db = @mysql_pconnect( $host, $user, $pass )or die( "<font face=\"arial\"><b>phpDHCPAdmin currently not active, is under repair or is not configured correctly.</b><br><br>Error Number: " . mysql_errno( $db ) . "<br>Error Message: " . mysql_error( $db ) . "<br>Email Administrator: <a href=\"mailto:$defined[5]\";>$defined[5]</a></font>" );
@mysql_select_db( $dbnam )or die( "<font face=\"arial\"><b>Could not connect to database: $defined[3]</b><br>Error Message: " . @mysql_error( $db ) . "<br>" . "Error Number: " . @mysql_errno( $db ) . "<br>Email Administrator: <a href=\"mailto:$defined[5]\";>$defined[5]</a></font>" );
return $db;
}


function logs() {
 global $defined;

db( $defined[9], $defined[1], $defined[2], $defined[3] );
$pagecount = "1";
$tble = "logs";
$sql = @mysql_query( "SELECT * FROM $tble WHERE session = \"$_SESSION[hash]\"", $db )

$db is not defined,
$db is not required,
at least if you want to use $db you have to ctach the return from db() in $db:


$db = db( $defined[9], $defined[1], $defined[2], $defined[3] );


as i assume, logs() does nothing more than update one row with session data in the DB?


if you have a primary key on `session` you can just user REPLACE instead of

"if SELECT INSERT ELSE UPDATE"

logs()
{
    db( $defined[9], $defined[1], $defined[2], $defined[3] );
    $sql = 'REPLACE INTO logs VALUES ( ... )';
    mysql_query( $sql ) or die( '...' );
}

--
Sebastian Mendel

www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com
www.sf.net/projects/phpdatetime        www.sf.net/projects/phptimesheet

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to