GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Mar-2004, 18:17
hellur hellur is offline
New Member
 
Join Date: Mar 2004
Posts: 1
hellur is on a distinguished road
Angry

well help pls... mysql // list databases php!


well this is my problem!

<?php
$host = "*****";
$user = "*****";
$pass = "*****";
$link = mysql_pconnect($host, $user, $pass);
$db_list = mysql_list_dbs( $link );
while ($row = mysql_fetch_object( $db_list ))
echo $row->Database;
mysql_close($link);
?>

okej thats nice... now to output?

------------------------------
test
------------------------------

Argh -hmm I have like 30 databases hmmm hmm... HELP
  #2  
Old 04-Mar-2004, 04:28
erniegerdie erniegerdie is offline
Junior Member
 
Join Date: Feb 2004
Location: England
Posts: 84
erniegerdie has a spectacular aura abouterniegerdie has a spectacular aura about
Quote:
Originally Posted by hellur
well this is my problem!

<?php
$host = "*****";
$user = "*****";
$pass = "*****";
$link = mysql_pconnect($host, $user, $pass);
$db_list = mysql_list_dbs( $link );
while ($row = mysql_fetch_object( $db_list ))
echo $row->Database;
mysql_close($link);
?>

Firstly I don't think you want to be using a permanent connection, which is created in the line:

$link = mysql_pconnect($host, $user, $pass);

I'm assuming this because your trying to close the connection with mysql_close, and this is not possible when you've made a permanent connection. Use mysql_connect instead.

After that I'm a bit lost on what you want to do? Do you want to retrieve the data in all databases ?

Well you could store the names of your databases into an array i.e
$dbnames[] = $row->Database;

You could then perform a select query on each of the databases:
foreach ($dbnames As $dbname) {
$result = msql_query("SELECT * FROM $dbname");
while($tmp = mysql_fetch_row($result))
dump data
}

For a more elequent way to retrieve the data from a mysql_fetch_row, check out the comments at: http://uk.php.net/manual/en/function...-fetch-row.php.

Hope this helps.

Added later:

I was thinking of mysql_fetch_array($result, MYSQL_NUM) syntax rather than mysql_fetch_row.
  #3  
Old 04-Mar-2004, 10:43
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
There's a glaring typo (or two) in your example code; so your first attempt should be to fix that...

PHP Code:

<?php
// ....
$db_list = mysql_list_dbs( $link );
while ($row = mysql_fetch_object( $db_list ))
{ // <-- MISSING
echo $row->Database;
} // <-- MISSING too
//.....

?>

  #4  
Old 04-Mar-2004, 10:54
Allowee's Avatar
Allowee Allowee is offline
Regular Member
 
Join Date: May 2003
Location: The Netherlands
Posts: 339
Allowee has a spectacular aura about
Sorry JdS..
but there is nothing wrong with that code

http://www.php.net/manual/en/control...ures.while.php
Quote:
Originally Posted by php.net
Like with the if statement, you can group multiple statements within the same while loop by surrounding a group of statements with curly braces, or by using the alternate syntax
not using the curcly braces only 'executes' one following statement
__________________
Pastebin
PHP Documentation Site
Allowee's Blog http://allowee.net
  #5  
Old 04-Mar-2004, 10:55
erniegerdie erniegerdie is offline
Junior Member
 
Join Date: Feb 2004
Location: England
Posts: 84
erniegerdie has a spectacular aura abouterniegerdie has a spectacular aura about
Quote:
Originally Posted by JdS
There's a glaring typo (or two) in your example code; so your first attempt should be to fix that...

PHP Code:

<?php
// ....
$db_list = mysql_list_dbs( $link );
while ($row = mysql_fetch_object( $db_list ))
{ // <-- MISSING
echo $row->Database;
} // <-- MISSING too
//.....

?>


If the code inside a while loop, if statement, for loop etc... is a one liner, then that code will run as far as i'm aware?
  #6  
Old 04-Mar-2004, 10:59
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Yes, I realised that as soon as I was redirected to the thread; since the message went in an email; I said f'it!

This is why I SHOULD refrain from replying to code issues when I am rushing
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FREE 25 MB, No Ads, Control Panel, ASP, ColdFusion, PHP, MySQL, Access Hosting rkmails Free Web Hosting 0 08-Sep-2003 06:49
600MB Space, 20GB Banwidth, PHP, MySQL, CGI, SSH, FrontPage, FTP, POP3, Web Mail fcolor Web Hosting Advertisements & Offers 0 08-Aug-2003 11:11
[script] Password Protect web pages/site using PHP and MySQL JdS PHP Code Library 0 23-Jul-2003 11:02
Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More EyotaHosts Web Hosting Advertisements & Offers 0 28-Jun-2003 14:54
Free Web Hosting: No Ads / Banners +FTP +PHP +MySQL +CGI JdS Free Web Hosting 5 26-May-2003 03:36

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:53.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.