michaellunsford Posted January 29, 2007 Share Posted January 29, 2007 I thought I had outsmarted the system, but no.I'm trying to pass the resource link identifier to a script via $_GET. I finally managed to get it working by creating my own function and using eval():[code]<?php function my_mysql_query($variable) { eval ("global $".$_GET['res_link'].";"); return (eval("return (mysql_query(\"".$variable."\",$".$_GET['res_link']."));"));}?>[/code]Now, the problem is mysql_real_escape_string() BLOB content, is bombing on me. [quote] Unexpected character in input: '' (ASCII=16) state=2 [/quote] it is noteworthy that it's presenting double single-quotes surrounding an unprintable character (which is refereced by it's ascii code), not a single double-quote. Also, this is the first warning in a long list.I guessed it's because the single escaped quotes are being unescaped for eval(). So, I [code=php:0]str_replace('"','\"',$variable)[/code] which is double-escaping quotes. But now I'm getting [quote] Unexpected character in input: '\' (ASCII=92) state=1 [/quote]so, now what? :( Quote Link to comment Share on other sites More sharing options...
toplay Posted January 29, 2007 Share Posted January 29, 2007 You can't and shouldn't do that.Topic moved to mysql forum. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 29, 2007 Author Share Posted January 29, 2007 Odd, the errors I'm getting I thought were related to my inability to pass the correct data to MySQL -- making it a PHP problem. Oh, well. Anyone here know how to fix, or why I should'nt do it this way?PS> this is behind a login, so only trusted folks have access. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 29, 2007 Author Share Posted January 29, 2007 yep, as I thought, it was an eval() problem (PHP side), not a MySQL problem. Apparently mysql_query() doesn't mind non-displaying characters, but eval() does. Here's how I fixed it:[code]<?phpfunction my_mysql_query($variable) { eval ("global $".$_GET['res_link'].";"); return (mysql_query($variable,eval("return ($".$_GET['res_link'].");")));}?>[/code] Quote Link to comment Share on other sites More sharing options...
toplay Posted January 30, 2007 Share Posted January 30, 2007 Once a PHP script ends the resource from a MySQL connection is closed (unless you are using persistent connections). So, there's no point in trying to pass them from page to page. You need to establish a new connection in each script.I don't know about now, but in the past MySQL persistent connections have caused lots of people on this forum many problems (and have led to server problems because too many persistent connects stay open and/or their resources aren't finally cleared out/closed properly).[quote=http://us2.php.net/manual/en/function.mysql-close.php]Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. [/quote]Regular flavor:http://us2.php.net/manual/en/function.mysql-connect.phpPersistent flavor:http://us2.php.net/manual/en/function.mysql-pconnect.phpYou think it's working because you're passing it, but it's really not. It's just creating a new resource link on the mysql_query().[quote=http://us2.php.net/manual/en/function.mysql-query.php]The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated.[/quote] Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 30, 2007 Author Share Posted January 30, 2007 ahh.. I see.As for the specific purpose here -- I'm including a PHP file with the opening connections -- and in some cases, there is more than one database open at a time. So, in those cases, it's important to know which databse I'm supposed to be modifying. Quote Link to comment Share on other sites More sharing options...
toplay Posted January 31, 2007 Share Posted January 31, 2007 In that case pass the database name (or a numeric code that signifies which DB to use to be more discreet), but it's best to pass that in sessions (instead of using GET in the URL). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.