1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php4 -> php5 function question?

Discussion in 'PHP' started by 123GoToAndPlay, Apr 21, 2009.

  1. #1
    In php4 i used this for a simple function

    
    function totProducts(){
    	global $database_connDB, $connDB;
    	mysql_select_db($database_connDB, $connDB);
    	$sql = "SELECT COUNT(*) as total FROM table";
    	$res = mysql_query($sql, $connDB) or die(mysql_error());
    	$row = mysql_fetch_assoc($res);
    	return $row['total'];
    }
    
    PHP:
    but now with php5 installed i get

    errors:
    Warning: mysql_select_db(): supplied argument is not a valid MySQL
    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in

    how do i fix this??

    regards

    edit: where can i find a common php4<->php5 list of differences?
     
    123GoToAndPlay, Apr 21, 2009 IP
  2. creativeGenius

    creativeGenius Well-Known Member

    Messages:
    273
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    #2
    creativeGenius, Apr 21, 2009 IP
  3. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    tx genius,

    can't check my php.ini but i know the mysql extension works. I see the value on my homepage, but i include the file (header.php) in other files. So that might be it.
    i added
    
    if (!function_exists("totProducts")) {
    
    }
    
    PHP:
    but still i get the errors
     
    123GoToAndPlay, Apr 21, 2009 IP
  4. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hmm i think it has to do with global and require_once('connDB.php'), perhaps

    
     global $database_connDB, $connDB;
    
    PHP:
     
    123GoToAndPlay, Apr 21, 2009 IP
  5. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ok think i found a solution
    
    if (!function_exists("totProducts")) {
    function totProducts(){
    	@require('connDB.php');
    	//global $database_connDB, $connDB;
    	mysql_select_db($database_connDB, $connDB);
    	$sql = "SELECT COUNT(*) as total FROM table";
    	$res = mysql_query($sql, $connDB) or die(mysql_error());
    	$row = mysql_fetch_assoc($res);
    	return $row['total'];
    }
    }
    
    PHP:
    any feedback?
     
    123GoToAndPlay, Apr 21, 2009 IP
  6. darren884

    darren884 Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try setting this in the PHP5 script:
    ini_set('register_globals', 'on');

    PHP5 turns globals off.

    Make sure that is at the top.
     
    darren884, Apr 21, 2009 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Or not. There is a reason for register_globals being OFF, mainly security reasons.
     
    PoPSiCLe, Apr 21, 2009 IP
  8. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #8
    use the mysql query "use databasename" to select database
    mysql_select_database is deprecated
     
    buldozerceto, Apr 22, 2009 IP