Jump to content

passing resource type parameters to a function


Balto

Recommended Posts

Dear all,
the following PHP script produces the warnings

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
in fetchArray function

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource
in releaseQuery function

is there a way to tell these function that we are passing a resource for them?

thanks,
balto



function connectMydb(){
$link=mysql_connect('localhost', 'mydb', 'pass') or die ('could not connect to Database');
mysql_select_db("mydbases");
return $link;
}

//--------------------------------- Query ------------------------------------
function queryMydb($stmt){
return mysql_query ($stmt) or die (mysql_error());
}

//------------------------------- Release Query ---------------------------
function releaseQuery($query){
mysql_free_result ($query);
}
//----------------------------- fetch a row ---------------------------------
function fetchArray ($query){
return mysql_fetch_array($query, MYSQL_ASSOC);
}

$link = connectMydb();
$result=queryMydb("select * from mytable");
$row=fetchArray($result);
//.... do something with data.
Link to comment
Share on other sites

well, mainly because I want the same code to be able to sit on mysql and odbc databases. now the functions follow the same paradigm but have different names. I figured that a layer of abstraction would help provide independency from the underlying engine.

anyway, since resource variables are just pointers to resources, they must be the easiest thing to pass to functions, like many other languages. it is strange that PHP doesn't allow them to be declared. I wonder if there is a reason or a workaround.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.