Hello and thanks for reading my question. I'm trying to make two little functions to add to an already exsisting db.php file.
They are as follows
/**
* get Number of affected rows
**/
FUNCTION dbNumRows( $result )
{
GLOBAL $MySQL;
RETURN mysql_num_rows( $result );
}
/**
* insert ID
**/
FUNCTION dbInsertId()
{
GLOBAL $MySQL;
RETURN mysql_insert_id( $MySQL->link );
} //end function dbInsertId
In the db.php file there is a class and function for connection
CLASS SQLCon
{
VAR $host, $sock, $port, $user, $passwd, $db, $connected, $link, $msgttl, $msgbdy;
FUNCTION connect() {
IF ( $this->connected ) {
RETURN;
}
IF ( strlen( $this->port ) ) {
$this->port = ":".$this->port;
}
IF ( strlen( $this->sock ) ) {
$this->sock = ":".$this->sock;
}
IF ( !DEFINED( 'DB_VERM' ) OR DB_VERM == 0 ) {
# ( @ ) DO NOT Display All VERM ( NORMAL Mode ) Normal Connection surpesses all warnings / errors
FOR ( $i = 0; $i < 75; $i++ ) {
IF ( !$this->link = @mysql_pconnect( $this->host . $this->port . $this->sock, $this->user, $this->passwd ) ) {
usleep(50000); #Not available on windows before PHP 5.0
}ELSE{
BREAK;
}
}#[ END ] 1st FOR ( $i = 0; $i < DB_ATTEMPTS; $i++ )
}ELSE{
# No ( @ ) Display All VERM ( DEBUG Mode ) Do not surpress warnings / errors
FOR ( $i = 0; $i < 75; $i++ ) {
IF ( !$this->link = mysql_pconnect( $this->host . $this->port . $this->sock, $this->user, $this->passwd ) ) {
usleep(50000); #Not available on windows before PHP 5.0
}ELSE{
BREAK;
}
}#[ END ] 2nd FOR ( $i = 0; $i < DB_ATTEMPTS; $i++ )
}#[ END ] IF ( !DEFINED( 'DB_VERM' ) OR DB_VERM == 0 )
IF ( $this->link ) {
$this->connected = TRUE;
}ELSE{
$this->connected = FALSE;
$out = "";
$out .= "<table align=center border=\"1\" cellpadding=\"2\" cellspacing=\"2\" style=\"border-color:$err_color\"><tr><td bgcolor=\"#9C21A5\">";
$out .= "<font color=white face=\"Arial, Helvetica, sans-serif\"><b>";
$out .= $this->msgttl;
$out .= "</b></font></td></tr>";
$out .= "<tr><td>";
$out .= $this->msgbdy;
$out .= "</td></tr></table>";
ECHO $out;
EXIT();
}
}# [ END ] FUNCTION connect()
FUNCTION select_db() {
IF ( !DEFINED( 'DB_VERM' ) OR DB_VERM == 0 ) {
RETURN @mysql_select_db( $this->db );# No ( @ ) Display All VERM ( DEBUG Mode )
}ELSE{
RETURN mysql_select_db( $this->db ); # ( @ ) DO NOT Display All VERM ( NORMAL Mode )
}
}# [ END ] FUNCTION select_db ()
}
$MySQL = NEW SQLCon;
$MySQL->host = $db['host'];
$MySQL->sock = $db['sock'];
$MySQL->port = $db['port'];
$MySQL->user = $db['user'];
$MySQL->passwd = $db['passwd'];
$MySQL->db = $db['db'];
$MySQL->msgttl = $db['msgttl'];
$MySQL->msgbdy = $db['msgbdy'];
$MySQL->connected = FALSE;
$MySQL->connect();
$MySQL->select_db();
/**
* db_connect() Connect to data base
**/
FUNCTION db_connect()
{
GLOBAL $MySQL;
$Code = 100;
IF ( !$MySQL->select_db() ) {
$SqlError = $_SERVER["PHP_SELF"]." : ". mysql_error();
$Msg = dbErrorMessage( $Code, "Database connection failed Error Code", $SqlError , "db_connect()" );
IF ( !DEFINED( 'DB_VERM' ) OR DB_VERM == 0 ) {# Only send mail when not in debug mode
dbPostOffice( $Msg, "dBase Error Report" );
ECHO dbPrintError( $Msg , "MemberPageDisplay");
}
IF ( DB_VERM == 1 ) {
ECHO dbPrintError( $Msg , "VERM");
}
EXIT();
}
RETURN TRUE;
}
A Known working function looks like this
/**
* db_res Data base res query
**/
FUNCTION db_res( $Query, $Display = FALSE )
{
GLOBAL $MySQL;
$Code = 103;
$n = 0;
IF ( !DEFINED( 'DB_VERM' ) OR DB_VERM == 0 AND !$Display ) {
$Res = @mysql_query( $Query, $MySQL->link );
}ELSE{
$Res = mysql_query( $Query, $MySQL->link );
}
IF ( !$Res ) {
$SqlError = $_SERVER["PHP_SELF"]." : ". mysql_error();
$Msg = dbErrorMessage( $Code, $Query, $SqlError , "db_res" );
IF ( !DEFINED( 'DB_VERM' ) OR DB_VERM == 0 ) {# Only send mail when not in debug mode
dbPostOffice( $Msg, "dBase Error Report" );
dbPrintError( $Msg , "MemberPageDisplay");
}
IF ( DB_VERM == 1 ) {
ECHO dbPrintError( $Msg , "VERM");
}
EXIT();
}
IF ( DEFINED('DB_VERM') AND DB_VERM == 2 ) {
$Msg = dbErrorMessage( $Code, $Query, "DB_VERM_QUERY = TRUE in header.inc.php" , "db_res" );
ECHO dbPrintError( $Msg , "VERM");
IF ( $Display ) {
ECHO "<br><br>Query Display = " . $Query;
WHILE( $Arr = mysql_fetch_array( $Res ) ) {
ECHO "<br>db Result ". $n ." = ";
PRINT_R( $Arr );
$n++;
}
}
}
RETURN $Res;
}
My question is do I use $MySQL->link in
mysql_num_rows( $MySQL->link );
and
mysql_insert_id( $MySQL->link );
Or does it need to do something like this
/**
* get Number of affected rows
**/
FUNCTION dbNumRows( $result )
{
GLOBAL $MySQL;
RETURN mysql_num_rows( $result, $MySQL->link );
}
Where the value of $result would be the result of doing db_res($myquery);
i.e.
$TotalNumber =dbNumRows( db_res( $myquery ) )