Jump to content

MySQL dynamic resource link identifier?


michaellunsford

Recommended Posts

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?  :(
Link to comment
Share on other sites

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]<?php
function my_mysql_query($variable) {
eval ("global $".$_GET['res_link'].";");
return (mysql_query($variable,eval("return ($".$_GET['res_link'].");")));
}
?>[/code]
Link to comment
Share on other sites

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.php

Persistent flavor:
http://us2.php.net/manual/en/function.mysql-pconnect.php

You 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]


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.