[PHP] setting function variables
I am trying to specify a single php file to contain all the variables and I just call this file where necessary. What I am running into is that I want to do this for all the built in functions (i.e. mssql_query) as well. I've tried numerous attempts but can't get it to operate without wanting to run the functions or return an error. Something like this: $runQuery = @mssql_query; $qryResults = @mssql_result; $getRow = @mssql_fetch_row; $getRowNums = @mssql_num_rows; I've tried using the %, $, ,'', and the @ symbol without any luck. Anyone know of way to do this, so I can use a generic name for all the functions and be able to distribute it to those using either SQL Server or MySQL without them having to go through the code and manually change it? thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setting function variables
--- CPT John W. Holmes [EMAIL PROTECTED] wrote: A good suggestion, since this is what your creating, basically. Anyhow, if you really want to do it your way, it'd be like this: $runQuery = 'mssql_query'; $getRow = 'mssql_fetch_row'; Then you'd use them like this: $result = $runQuery(select ... ); while($row = $getRow($result)) { ... } I seem to learn something new every time you or Jennifer post (many others as well). I never knew about variable functions. Cool! ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] setting function variables
[snip] I am trying to specify a single php file to contain all the variables and I just call this file where necessary. What I am running into is that I want to do this for all the built in functions (i.e. mssql_query) as well. I've tried numerous attempts but can't get it to operate without wanting to run the functions or return an error. Something like this: $runQuery = @mssql_query; $qryResults = @mssql_result; $getRow = @mssql_fetch_row; $getRowNums = @mssql_num_rows; I've tried using the %, $, ,'', and the @ symbol without any luck. Anyone know of way to do this, so I can use a generic name for all the functions and be able to distribute it to those using either SQL Server or MySQL without them having to go through the code and manually change it? [/snip] This may help, http://us4.php.net/manual/en/functions.variable-functions.php Have a pleasant day! :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] setting function variables
Tried this and it returns errors of type: Warning: Wrong parameter count for mssql_result() in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 78 Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 79 Lines 78 and 79 read like this: $img_numbers = $qryResults(SELECT COUNT(img_id) AS TotalImages FROM images WHERE category_id = '$row[0]'); $img_count = $qryResults($img_numbers,0,TotalImages) The variables are specified as $runQuery = 'mssql_query'; $qryResults = 'mssql_result'; You are using mssql_result instead of mssql_query on line 78. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setting function variables
From: Mark [EMAIL PROTECTED] --- Micah Montoy [EMAIL PROTECTED] wrote: I am trying to specify a single php file to contain all the variables and I just call this file where necessary. What I am running into is that I want to do this for all the built in functions (i.e. mssql_query) as well. I've tried numerous attempts but can't get it to operate without wanting to run the functions or return an error. Something like this: $runQuery = @mssql_query; $qryResults = @mssql_result; $getRow = @mssql_fetch_row; $getRowNums = @mssql_num_rows; Use a database abstraction class (ADODB, Pear, or something from phpclasses.org). You're trying to assign a variable to a function's actions, when you can only assign the variable to teh ooutput of the function. A good suggestion, since this is what your creating, basically. Anyhow, if you really want to do it your way, it'd be like this: $runQuery = 'mssql_query'; $getRow = 'mssql_fetch_row'; Then you'd use them like this: $result = $runQuery(select ... ); while($row = $getRow($result)) { ... } ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setting function variables
--- Micah Montoy [EMAIL PROTECTED] wrote: Tried this and it returns errors of type: Warning: Wrong parameter count for mssql_result() in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 78 Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 79 Warning: Wrong parameter count for mssql_result() in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 78 Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 79 Lines 78 and 79 read like this: $img_numbers = $qryResults(SELECT COUNT(img_id) AS TotalImages This should be $runQuery(), not $qryResults() FROM images WHERE category_id = '$row[0]'); $img_count = $qryResults($img_numbers,0,TotalImages) The variables are specified as $runQuery = 'mssql_query'; $qryResults = 'mssql_result'; Any ideas of why it would be doing this? Everything works fine when I don't try to use the variables. thanks Cpt John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] From: Mark [EMAIL PROTECTED] --- Micah Montoy [EMAIL PROTECTED] wrote: I am trying to specify a single php file to contain all the variables and I just call this file where necessary. What I am running into is that I want to do this for all the built in functions (i.e. mssql_query) as well. I've tried numerous attempts but can't get it to operate without wanting to run the functions or return an error. Something like this: $runQuery = @mssql_query; $qryResults = @mssql_result; $getRow = @mssql_fetch_row; $getRowNums = @mssql_num_rows; Use a database abstraction class (ADODB, Pear, or something from phpclasses.org). You're trying to assign a variable to a function's actions, when you can only assign the variable to teh ooutput of the function. A good suggestion, since this is what your creating, basically. Anyhow, if you really want to do it your way, it'd be like this: $runQuery = 'mssql_query'; $getRow = 'mssql_fetch_row'; Then you'd use them like this: $result = $runQuery(select ... ); while($row = $getRow($result)) { ... } ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setting function variables
Micah Montoy [EMAIL PROTECTED] wrote: Anyone know of way to do this, so I can use a generic name for all the functions and be able to distribute it to those using either SQL Server or MySQL without them having to go through the code and manually change it? use Pear's DB abstraction layer module check it out at: http://pear.php.net regards, Juan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setting function variables
From: Mark [EMAIL PROTECTED] I seem to learn something new every time you or Jennifer post (many others as well). I never knew about variable functions. Cool! You're welcome. I wouldn't recommend that solution exactly (an abstraction class would be better), but the functions do come in handy. For example, I use variable function in one of my validation classes. I have a main method called check() that is passed a type and a value. The type must match a method in the class. The check() method does some default checking and then passes the $value to the $type() method for further checking... class Validate { function check($type,$value) { if($empty($value)) { return FALSE; } if(method_exists($this,$type)) { $retval = $this-$type($value); } return $retval; } function number($value) { if(preg_match('/[^0-9]/',$value)) { return FALSE; } else { return $value; } } } Where number is one of the types that'll be validated. $val = new Validate; $val-check('number',$_POST['somevalue']); $val-check('date',$_POST['somedate']); $val-check('phone',$_POST['phone_number']); etc... Where you'd have a phone() and date() method in the Validate class... I think that's the only place I've used variable-functions... or variable-methods, rather. :) ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setting function variables
Tried this and it returns errors of type: Warning: Wrong parameter count for mssql_result() in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 78 Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 79 Warning: Wrong parameter count for mssql_result() in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 78 Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 79 Lines 78 and 79 read like this: $img_numbers = $qryResults(SELECT COUNT(img_id) AS TotalImages FROM images WHERE category_id = '$row[0]'); $img_count = $qryResults($img_numbers,0,TotalImages) The variables are specified as $runQuery = 'mssql_query'; $qryResults = 'mssql_result'; Any ideas of why it would be doing this? Everything works fine when I don't try to use the variables. thanks Cpt John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] From: Mark [EMAIL PROTECTED] --- Micah Montoy [EMAIL PROTECTED] wrote: I am trying to specify a single php file to contain all the variables and I just call this file where necessary. What I am running into is that I want to do this for all the built in functions (i.e. mssql_query) as well. I've tried numerous attempts but can't get it to operate without wanting to run the functions or return an error. Something like this: $runQuery = @mssql_query; $qryResults = @mssql_result; $getRow = @mssql_fetch_row; $getRowNums = @mssql_num_rows; Use a database abstraction class (ADODB, Pear, or something from phpclasses.org). You're trying to assign a variable to a function's actions, when you can only assign the variable to teh ooutput of the function. A good suggestion, since this is what your creating, basically. Anyhow, if you really want to do it your way, it'd be like this: $runQuery = 'mssql_query'; $getRow = 'mssql_fetch_row'; Then you'd use them like this: $result = $runQuery(select ... ); while($row = $getRow($result)) { ... } ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setting function variables
Use a database abstraction class (ADODB, Pear, or something from phpclasses.org). You're trying to assign a variable to a function's actions, when you can only assign the variable to teh ooutput of the function. --- Micah Montoy [EMAIL PROTECTED] wrote: I am trying to specify a single php file to contain all the variables and I just call this file where necessary. What I am running into is that I want to do this for all the built in functions (i.e. mssql_query) as well. I've tried numerous attempts but can't get it to operate without wanting to run the functions or return an error. Something like this: $runQuery = @mssql_query; $qryResults = @mssql_result; $getRow = @mssql_fetch_row; $getRowNums = @mssql_num_rows; I've tried using the %, $, ,'', and the @ symbol without any luck. Anyone know of way to do this, so I can use a generic name for all the functions and be able to distribute it to those using either SQL Server or MySQL without them having to go through the code and manually change it? thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setting function variables
Ooops. Can't believe I overlooked that. Thanks everyone for your input. Its up and running now. - Original Message - From: Mark [EMAIL PROTECTED] To: Micah Montoy [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, August 07, 2003 2:36 PM Subject: Re: [PHP] setting function variables --- Micah Montoy [EMAIL PROTECTED] wrote: Tried this and it returns errors of type: Warning: Wrong parameter count for mssql_result() in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 78 Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 79 Warning: Wrong parameter count for mssql_result() in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 78 Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in c:\inetpub\wwwroot\webpage10\example\utilities\dsp_del_images.php on line 79 Lines 78 and 79 read like this: $img_numbers = $qryResults(SELECT COUNT(img_id) AS TotalImages This should be $runQuery(), not $qryResults() FROM images WHERE category_id = '$row[0]'); $img_count = $qryResults($img_numbers,0,TotalImages) The variables are specified as $runQuery = 'mssql_query'; $qryResults = 'mssql_result'; Any ideas of why it would be doing this? Everything works fine when I don't try to use the variables. thanks Cpt John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] From: Mark [EMAIL PROTECTED] --- Micah Montoy [EMAIL PROTECTED] wrote: I am trying to specify a single php file to contain all the variables and I just call this file where necessary. What I am running into is that I want to do this for all the built in functions (i.e. mssql_query) as well. I've tried numerous attempts but can't get it to operate without wanting to run the functions or return an error. Something like this: $runQuery = @mssql_query; $qryResults = @mssql_result; $getRow = @mssql_fetch_row; $getRowNums = @mssql_num_rows; Use a database abstraction class (ADODB, Pear, or something from phpclasses.org). You're trying to assign a variable to a function's actions, when you can only assign the variable to teh ooutput of the function. A good suggestion, since this is what your creating, basically. Anyhow, if you really want to do it your way, it'd be like this: $runQuery = 'mssql_query'; $getRow = 'mssql_fetch_row'; Then you'd use them like this: $result = $runQuery(select ... ); while($row = $getRow($result)) { ... } ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] setting function variables
I am trying to specify a single php file to contain all the variables and I just call this file where necessary. What I am running into is that I want to do this for all the built in functions (i.e. mssql_query) as well. I've tried numerous attempts but can't get it to operate without wanting to run the functions or return an error. Something like this: $runQuery = @mssql_query; $qryResults = @mssql_result; $getRow = @mssql_fetch_row; $getRowNums = @mssql_num_rows; I've tried using the %, $, ,'', and the @ symbol without any luck. Anyone know of way to do this, so I can use a generic name for all the functions and be able to distribute it to those using either SQL Server or MySQL without them having to go through the code and manually change it? thanks Have you looked into variable functions? http://www.php.net/manual/en/functions.variable-functions.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php