RE: [PHP] mysql_list_fields() bug?
[snip] Ok, this ended up working well. I'm still wondering why in my example function two() works, without needing to provide the resource identifier to mysql_query(), how can mysql_query() pick up the resource identifier automatically while mysql_list_fields does not? [/snip] From http://www.php.net/mysql_query mysql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. --If link_identifier isn't specified, the last opened link is assumed.-- If no link is open, the function tries to establish a link as if mysql_connect() was called with no arguments, and use it. The result of the query is buffered. mysql_list_fields() does not automagically use the last opened link -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql_list_fields() bug?
Hey All - just wanted to check in with anyone who has used this function. I currectly have a function that I created, and inside it I have this function. Outside of my custom function I have a mysql_pconnect() statement and a mysql_select_db() statement. I also have another custom function that runs a SQL query and returns the results. My problem is why does the custom function with mysql_list_fields(), fail to run unless I put a separate pconnect and select_db statement in the custom function itself and my other custom function can query the DB fine. $db = mysql_pconnect(ip, user, password); mysql_select_db(db); function one() { $db = mysql_pconnect(ip, user, password); mysql_select_db(db); $fields = mysql_list_fields(db, table); } function two() { $q = SELECT * FROM user; $result = mysql_query($q); return $result; } So the end result being if I take the connect statement out of the function one(), it fails, but function two() still works! Am I doing something wrong here? Thanks, Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] mysql_list_fields() bug?
[snip] Outside of my custom function I have a mysql_pconnect() statement and a mysql_select_db() statement. So the end result being if I take the connect statement out of the function one(), it fails, but function two() still works! Am I doing something wrong here? [/snip] It's just a small misunderstanding Matt. Your $db = mysql_pconnect(ip, user, password); is LOCAL to the function http://us3.php.net/language.variables.scope The other connection string you mention sits OUTSIDE of any other function, so it is GLOBAL (you didn't show that code). You are not calling for the GLOBAL connection in function one. As someone famous once said, Location, location, location! If you add the resource identifier to the request in function one to $fields = mysql_list_fields(db, table, $db); it should work just fin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] mysql_list_fields() bug?
On Mon, 2003-11-10 at 16:43, Jay Blanchard wrote: [snip] Outside of my custom function I have a mysql_pconnect() statement and a mysql_select_db() statement. So the end result being if I take the connect statement out of the function one(), it fails, but function two() still works! Am I doing something wrong here? [/snip] It's just a small misunderstanding Matt. Your $db = mysql_pconnect(ip, user, password); is LOCAL to the function http://us3.php.net/language.variables.scope The other connection string you mention sits OUTSIDE of any other function, so it is GLOBAL (you didn't show that code). You are not calling for the GLOBAL connection in function one. As someone famous once said, Location, location, location! If you add the resource identifier to the request in function one to $fields = mysql_list_fields(db, table, $db); it should work just fin Ok, I added the resource identifier, and got an error. I think what is happening now is the resource identifier $db is outside the function one(), so it cannot be referenced from the mysql_list_fields() fuction which is inside. Does that make sense? Is the resource indentifier a GLOBAL thing, because I sure didn't make it one :) The error I got was, supplied argument is not a valid Mysql-Link resource. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] mysql_list_fields() bug?
[snip] Ok, I added the resource identifier, and got an error. I think what is happening now is the resource identifier $db is outside the function one(), so it cannot be referenced from the mysql_list_fields() fuction which is inside. Does that make sense? Is the resource indentifier a GLOBAL thing, because I sure didn't make it one :) The error I got was, supplied argument is not a valid Mysql-Link resource. [/snip] Add GLOBAL to the function function one() { global $db; mysql_select_db(db); $fields = mysql_list_fields(db, table, $db); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] mysql_list_fields() bug?
as said, use the global construct. This is a scope problem, read the manual about variable scope. php.net/variables.scope PS: sorry Jay, new mail frontend :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] mysql_list_fields() bug?
Ok, this ended up working well. I'm still wondering why in my example function two() works, without needing to provide the resource identifier to mysql_query(), how can mysql_query() pick up the resource identifier automatically while mysql_list_fields does not? Thx- Matt On Mon, 2003-11-10 at 17:00, Jay Blanchard wrote: [snip] Ok, I added the resource identifier, and got an error. I think what is happening now is the resource identifier $db is outside the function one(), so it cannot be referenced from the mysql_list_fields() fuction which is inside. Does that make sense? Is the resource indentifier a GLOBAL thing, because I sure didn't make it one :) The error I got was, supplied argument is not a valid Mysql-Link resource. [/snip] Add GLOBAL to the function function one() { global $db; mysql_select_db(db); $fields = mysql_list_fields(db, table, $db); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php