Re: [PHP-DB] PHP accessing MySQL
OK, I have found some more time to work on my PHP project. The problem is indicated in the following line: $tables = mysql_list_tables($db_names[$db_num]) or die(Couldn't list databases.); I took the variable $db_num and replaced it with a value of 1 as follows: $tables = mysql_list_tables($db_names[1]) or die(Couldn't list databases.); The output gave me the following results: The value of db_list is: mysql test twignud The value of dbs is: Resource id #2 The value of db_num is: 3 If I replace $db_num with a value of 0, 2 or 3 I get Couldn't list databases. Any ideas anyone? Julie? Miles? Could this have anything to do with mysql user permission? Thanks, jkd Jonathan Duncan [EMAIL PROTECTED] wrote in message 9eekpb$s41$[EMAIL PROTECTED]">news:9eekpb$s41$[EMAIL PROTECTED]... YES!! I just had a feeling the book was wrong. That did get rid of the error. However, it did not completely solve my issue. Now when I run the script I just get the message Couldn't list databases. This just happens to be the die message for the same line of code that I have been looking at: $tables = mysql_list_tables($db_names[$db_num]) or die(Couldn't list databases.); It is almost as if it is not being able to even list the tables from the databases. I am working right now on just listing the tables of a database to see what happens. Thank you, jkd Julie Meloni [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I believe you want to look at this page: http://www.thickbook.com/books/phpfe_errata.phtml -- ++ | Julie Meloni ([EMAIL PROTECTED]) | || | PHP Essentials and PHP Fast Easy | | http://www.thickbook.com | ++ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] PHP accessing MySQL
That is what I thought, so I set $db_num to another number and still came up with the same error. jkd Darren [EMAIL PROTECTED] wrote in message 9e42lj$s7b$[EMAIL PROTECTED]">news:9e42lj$s7b$[EMAIL PROTECTED]... I think the 0 is referring to your $db_num Jonathan Duncan [EMAIL PROTECTED] wrote in message 9e3suq$17r$[EMAIL PROTECTED]">news:9e3suq$17r$[EMAIL PROTECTED]... I am making a script to access MySQL and when I run it I get this: Warning: 0 is not a MySQL link index in /sites/htdocs/php/db_listtables.php on line 10 Following is the first 10 lines of my script: ? $connection = mysql_connect(localhost, user, password) or die(Couldn't connect.); $dbs = mysql_list_dbs($connection) or die(Couldn't list databases.); $db_list = UL; $db_num = 0; while ($db_num mysql_num_rows($dbs)) { $db_names[$db_num] = mysql_tablename($dbs, $db_num); $db_list .= LI$db_names[$db_num]; if (($db_names[$db_num] != mysql) ($db_names[$db_num] != tempdata)) { $tables = mysql_list_dbs($db_names[$db_num]) or die(Couldn't list databases.); Any Ideas? Thank you in advance!! Jonathan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] PHP accessing MySQL
Miles Thompson [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Jonathan .. see below. At 08:38 PM 5/18/01 +, Jonathan Duncan wrote: Miles Thank you for the response. I did some debugging and the value of $dbs is 2. I am not sure of what example you are referring to. I am not using the manual currently, although I have the PDF version of it. http://www.php.net/mysql_list_dbs for on line version, with annotations! I tried the example found on the site: while ($row = mysql_fetch_object($dbs)) { echo $row-Database . \n; } And the results were null. It listed nothing. I have a question about this example, what is the - supposed to do? The incrementation of $db_num happens on line 24 but I only listed the first 10 lines because it seems to be a problem within the first 10 lines as the error message indicates. If I change line 10 from: $tables = mysql_list_dbs($db_names[$db_num]) to: $tables = mysql_list_dbs() the script runs and gives me a list of the databases redundantly: -mysql -test mysql test twignud -twignud mysql test twignud Cool! Although it's not what you want. g. But what is it telling us? We're just running through two loops, but really asking for the same information each time, if I interpret it correctly. And if you look at your code, you have two nested loops, doing essentially the same thing - listing the databases. That is pretty much what I am trying to do. I want to list each database and then the tables within those databases. ? $connection = mysql_connect(localhost, user, password) or die (Couldn't connect.); $dbs = mysql_list_dbs($connection) or die(Couldn't list databases.); $db_list = UL; $db_num = 0; while ($db_num mysql_num_rows($dbs)) { $db_names[$db_num] = mysql_tablename($dbs, $db_num); $db_list .= LI$db_names[$db_num]; if (($db_names[$db_num] != mysql) ($db_names[$db_num] ! = tempdata)) { $tables = mysql_list_dbs($db_names[$db_num]) or die(Couldn't list databases.); $tables = mysql_list_dbs() or die(Couldn't list databases.); $table_list = UL; $table_num = 0; while ($table_num mysql_num_rows($tables)) { $table_names[$table_num] = mysql_tablename($tables, $table_num); $table_list .= LI$table_names[$table_num]; $table_num++; } $table_list .= /UL; } $db_list .= $table_list; $db_num++; } $db_list .= /UL; ? This is minus my debugging additions. I tried to get info from $mysql_tablename but it came up blank every way I tried it. It is as though nothing is getting passed into $mysql_tablename. That's strange, because this annotation came from zak@php: [Editor's Note: mysql_db_name(), mysql_dbname() and mysql_tablename() are all aliases for mysql_result() and should behave in exactly the same fashion. [EMAIL PROTECTED]] Use mysql_db_name() instead of mysql_tablename() to read databases. http://php.net/manual/en/function.mysql-db-name.php So this should give us a list of keys and databases: while( $row = mysql_fetch_array( $dbs ) ) { echo $row[ 0 ]; echo $row[ 1 ]; } while($row = mysql_fetch_array($dbs)) { echo Row 0 is , $row[0]; echo Row 1 is , $row[1]; } Returns: Row 0 is mysqlRow 1 is Row 0 is testRow 1 is Row 0 is twignudRow 1 is -IE- Row 0 is mysql Row 1 is Row 0 is test Row 1 is Row 0 is twignud Row 1 is I'm wondering, if $row[ 0 ] returns the name of the database, and $row[ 1 ] returns array. (Or vice versa.) If so, we should be able to nest another while () in there and fetch the table names. (If that's your intention.) I'll warn you that I get lost in multi-dimensional arrays very quickly, and I'm freelancing this off the top of my head. It seems that Row 1 doesn't have anything which may be the source of the problem. What do you think of this? Does this clarify anything in your mind? I am taking this script straight from a book. However, the book is designed for PHP 4 and I am using PHP 3.0.16, although I don't know if that would make a difference. Shouldn't, but is there any reason why you can't go to 4.0.5? Why not get the database names loop working first, and then go for the table names, a divide and conquer approach. Sounds like a good plan, I will see what I can do. Thank you very much for your help, Jonathan My pleasure - you're digging on it too. Miles Yep, I love this stuff! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] PHP accessing MySQL
I believe you want to look at this page: http://www.thickbook.com/books/phpfe_errata.phtml -- ++ | Julie Meloni ([EMAIL PROTECTED]) | || | PHP Essentials and PHP Fast Easy | | http://www.thickbook.com | ++ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] PHP accessing MySQL
YES!! I just had a feeling the book was wrong. That did get rid of the error. However, it did not completely solve my issue. Now when I run the script I just get the message Couldn't list databases. This just happens to be the die message for the same line of code that I have been looking at: $tables = mysql_list_tables($db_names[$db_num]) or die(Couldn't list databases.); It is almost as if it is not being able to even list the tables from the databases. I am working right now on just listing the tables of a database to see what happens. Thank you, jkd Julie Meloni [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I believe you want to look at this page: http://www.thickbook.com/books/phpfe_errata.phtml -- ++ | Julie Meloni ([EMAIL PROTECTED]) | || | PHP Essentials and PHP Fast Easy | | http://www.thickbook.com | ++ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] PHP accessing MySQL
I think the 0 is referring to your $db_num Jonathan Duncan [EMAIL PROTECTED] wrote in message 9e3suq$17r$[EMAIL PROTECTED]">news:9e3suq$17r$[EMAIL PROTECTED]... I am making a script to access MySQL and when I run it I get this: Warning: 0 is not a MySQL link index in /sites/htdocs/php/db_listtables.php on line 10 Following is the first 10 lines of my script: ? $connection = mysql_connect(localhost, user, password) or die(Couldn't connect.); $dbs = mysql_list_dbs($connection) or die(Couldn't list databases.); $db_list = UL; $db_num = 0; while ($db_num mysql_num_rows($dbs)) { $db_names[$db_num] = mysql_tablename($dbs, $db_num); $db_list .= LI$db_names[$db_num]; if (($db_names[$db_num] != mysql) ($db_names[$db_num] != tempdata)) { $tables = mysql_list_dbs($db_names[$db_num]) or die(Couldn't list databases.); Any Ideas? Thank you in advance!! Jonathan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] PHP accessing MySQL
Jonathan .. see below. At 08:38 PM 5/18/01 +, Jonathan Duncan wrote: Miles Thank you for the response. I did some debugging and the value of $dbs is 2. I am not sure of what example you are referring to. I am not using the manual currently, although I have the PDF version of it. http://www.php.net/mysql_list_dbs for on line version, with annotations! The incrementation of $db_num happens on line 24 but I only listed the first 10 lines because it seems to be a problem within the first 10 lines as the error message indicates. If I change line 10 from: $tables = mysql_list_dbs($db_names[$db_num]) to: $tables = mysql_list_dbs() the script runs and gives me a list of the databases redundantly: -mysql -test mysql test twignud -twignud mysql test twignud Cool! Although it's not what you want. g. But what is it telling us? We're just running through two loops, but really asking for the same information each time, if I interpret it correctly. And if you look at your code, you have two nested loops, doing essentially the same thing - listing the databases. ? $connection = mysql_connect(localhost, user, password) or die (Couldn't connect.); $dbs = mysql_list_dbs($connection) or die(Couldn't list databases.); $db_list = UL; $db_num = 0; while ($db_num mysql_num_rows($dbs)) { $db_names[$db_num] = mysql_tablename($dbs, $db_num); $db_list .= LI$db_names[$db_num]; if (($db_names[$db_num] != mysql) ($db_names[$db_num] ! = tempdata)) { $tables = mysql_list_dbs($db_names[$db_num]) or die(Couldn't list databases.); $tables = mysql_list_dbs() or die(Couldn't list databases.); $table_list = UL; $table_num = 0; while ($table_num mysql_num_rows($tables)) { $table_names[$table_num] = mysql_tablename($tables, $table_num); $table_list .= LI$table_names[$table_num]; $table_num++; } $table_list .= /UL; } $db_list .= $table_list; $db_num++; } $db_list .= /UL; ? This is minus my debugging additions. I tried to get info from $mysql_tablename but it came up blank every way I tried it. It is as though nothing is getting passed into $mysql_tablename. That's strange, because this annotation came from zak@php: [Editor's Note: mysql_db_name(), mysql_dbname() and mysql_tablename() are all aliases for mysql_result() and should behave in exactly the same fashion. [EMAIL PROTECTED]] Use mysql_db_name() instead of mysql_tablename() to read databases. http://php.net/manual/en/function.mysql-db-name.php So this should give us a list of keys and databases: while( $row = mysql_fetch_array( $dbs ) ) { echo $row[ 0 ]; echo $row[ 1 ]; } I'm wondering, if $row[ 0 ] returns the name of the database, and $row[ 1 ] returns array. (Or vice versa.) If so, we should be able to nest another while () in there and fetch the table names. (If that's your intention.) I'll warn you that I get lost in multi-dimensional arrays very quickly, and I'm freelancing this off the top of my head. Does this clarify anything in your mind? I am taking this script straight from a book. However, the book is designed for PHP 4 and I am using PHP 3.0.16, although I don't know if that would make a difference. Shouldn't, but is there any reason why you can't go to 4.0.5? Why not get the database names loop working first, and then go for the table names, a divide and conquer approach. Thank you very much for your help, Jonathan My pleasure - you're digging on it too. Miles Miles Thompson [EMAIL PROTECTED] said: Well, when you debug it, what do you get? What's the value of $dbs? Did you try the simple example shown in the manual, using your information. Did it work? I don't see where you are incrementing $db_num, that could be where your error is coming from. Also check to see if what you are getting back from mysql_tablename() is text or and index. Good luck - Miles Thompson At 01:33 PM 5/18/01 -0600, you wrote: I am making a script to access MySQL and when I run it I get this: Warning: 0 is not a MySQL link index in /sites/htdocs/php/db_listtables.php on line 10 Following is the first 10 lines of my script: ? $connection = mysql_connect(localhost, user, password) or die(Couldn't connect.); $dbs = mysql_list_dbs($connection) or die(Couldn't list databases.); $db_list = UL; $db_num = 0; while ($db_num mysql_num_rows($dbs)) { $db_names[$db_num] = mysql_tablename($dbs, $db_num); $db_list .= LI$db_names[$db_num]; if (($db_names[$db_num] != mysql) ($db_names[$db_num] ! = tempdata)) { $tables = mysql_list_dbs($db_names[$db_num]) or die(Couldn't list databases.); Any Ideas? Thank you in advance!! Jonathan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: