php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18819 mysqp_select_db() can't be called from within user defined functions
Submitted: 2002-08-08 20:07 UTC Modified: 2002-08-08 20:52 UTC
From: php at arc2 dot co dot uk Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.2.1 OS: Linux
Private report: No CVE-ID: None
 [2002-08-08 20:07 UTC] php at arc2 dot co dot uk
I've tested this extensively on PHP v4.2.1 and Apache v1.3.26...

can't get the function, mysql_select_db(), to work from within a user defined
function...
 
e.g. file "functions.php"...

include("config.php"); // database name etc.
$db = ("mydb");
    mysql_connect($hostname, $user, $pass) OR DIE("Unable to connect to database");
    
/* if you included the following code WITHIN the function, it won't work. It works as long as it's placed before the start of the function: */

mysql_select_db($db);

/* and here's the function */

function adminstuff() {

//    $result = mysql_query('SELECT uid, uname FROM users');
//   $resultrow = mysql_fetch_array($result);
//	return array ($resultrow[0], $resultrow[1]);

/* Select all users with the preference Apples */
$query = "SELECT * FROM users";

$result = MYSQL_QUERY($query);

/* How many of these users are there? */
$number = MYSQL_NUMROWS($result);
END---


The error returned is:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /functions.php on line 40

If one adds an OR DIE command to the end of the mysql_select_db() function, this is where the script halts.


Noel da Costa
www.arc2.co.uk

This code was running on ipowerweb.com web hosting servers, so I don't have access to gbd and all the technical gumf.

Apache Server Software: Apache/1.3.26 (Unix) mod_bwlimited/1.0 PHP/4.2.1 mod_log_bytes/0.3 FrontPage/5.0.2.2510 mod_ssl/2.8.9 OpenSSL/0.9.6b


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-08 20:52 UTC] georg@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC