icelandic Posted August 13, 2009 Share Posted August 13, 2009 Hello All, I want mysql_query to result in an warning/error if the link identifier from the mysql_connect is NOT used in the MySQL query. Example: $conn = mysql_connect("localhost", "username", "password"); mysql_select_db("dbname", $conn); $result = mysql_query("SELECT * FROM tablename', $conn); //No error $result = mysql_query("SELECT * FROM tablename'); //Could not connect to db error I'm working with objects and only want to be able to query inside the object, but for some reason, the connection stays open outside the object. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/170168-mysql_query-only-with-link-identifier/ Share on other sites More sharing options...
mikesta707 Posted August 13, 2009 Share Posted August 13, 2009 make your own function <?php function my_mysql_query($query, $link){ if (empty($link) && !isset($link)){ die("NO"); } mysql_query($query, $link); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170168-mysql_query-only-with-link-identifier/#findComment-897646 Share on other sites More sharing options...
icelandic Posted August 13, 2009 Author Share Posted August 13, 2009 The problem I'm trying to solve is keeping the connection in the $conn variable, not in the open. Even if I make my own function, another developer can write: $result = mysql_query("SELECT * FROM tablename'); outside the object and would have access to the connection. Quote Link to comment https://forums.phpfreaks.com/topic/170168-mysql_query-only-with-link-identifier/#findComment-897652 Share on other sites More sharing options...
icelandic Posted August 14, 2009 Author Share Posted August 14, 2009 *bump Quote Link to comment https://forums.phpfreaks.com/topic/170168-mysql_query-only-with-link-identifier/#findComment-898085 Share on other sites More sharing options...
icelandic Posted August 18, 2009 Author Share Posted August 18, 2009 *another bump Quote Link to comment https://forums.phpfreaks.com/topic/170168-mysql_query-only-with-link-identifier/#findComment-901072 Share on other sites More sharing options...
mikesta707 Posted August 18, 2009 Share Posted August 18, 2009 I don't think you can change the built in functions that PHP has. if you don't want to give access to your connection to anyone, you can close your connection after every query, but the mysql_query function will always have a default value for the link variable Quote Link to comment https://forums.phpfreaks.com/topic/170168-mysql_query-only-with-link-identifier/#findComment-901080 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.