Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 24th, 2000, 10:51 AM
12338323 12338323 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: eugene, or, us
Posts: 8 12338323 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to 12338323
Is it possible to refer to a table in a query statement, where the table name is a variable.
For example:
select * from $table where whatever

$table, being the a varable that contains the name of the table?

Thank you.

Reply With Quote
  #2  
Old January 25th, 2000, 06:53 AM
Imo Imo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 1999
Posts: 33 Imo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Yes.

Reply With Quote
  #3  
Old January 25th, 2000, 09:41 AM
12338323 12338323 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: eugene, or, us
Posts: 8 12338323 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to 12338323
Imo,

Do you know how to do it? When I tried to code a query, I recieved a Mysql error indicating that it was tring to look up the table database01.$table. (Assuming a database named database01 and refering to the table with the variable $table). It appeared to me that DBI was passing the variable name to Mysql in a literal fashion (i.e., the name of the variable and not the contents of the variable).

Thanks


Reply With Quote
  #4  
Old February 3rd, 2000, 09:56 AM
markdrayton markdrayton is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Oxford, England
Posts: 3 markdrayton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to markdrayton
Did you do "$table"? This would explain it.

Mark

Reply With Quote
  #5  
Old February 3rd, 2000, 10:20 AM
12338323 12338323 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: eugene, or, us
Posts: 8 12338323 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to 12338323
Mark,

Thank you. That was the problem. I completely overlooked the fact that I had single quoted my query statement....

It always ends up being something simple like that doesn't it.
Greg Zartman

Reply With Quote
  #6  
Old March 16th, 2000, 06:25 PM
bydavid bydavid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: USA
Posts: 67 bydavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
I have been having a similar problem. Would you mind showing me your database connection code? My code seems to get stuck on the
$sth=$dbh->prepare($SQL)

Reply With Quote
  #7  
Old March 16th, 2000, 06:29 PM
12338323 12338323 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: eugene, or, us
Posts: 8 12338323 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to 12338323
my $dbh = DBI->connect("dbi:mysql:$main_member_dbase", "$main_member_username", "$main_member_password") | | &p_error;
my($sth) = $dbh->prepare("SELECT * FROM $hit_table WHERE username = ? ") | | &p_error;
$sth->execute($user) | | &p_error;
@stat_array = $sth->fetchrow_array();
$sth->finish;
$dbh->disconnect;

Reply With Quote
  #8  
Old March 21st, 2000, 07:21 PM
yoshi yoshi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 108 yoshi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via ICQ to yoshi
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by bydavid:
I have been having a similar problem. Would you mind showing me your database connection code? My code seems to get stuck on the
$sth=$dbh->prepare($SQL)
[/quote]

check your assignment code for $SQL. I had the same problem, where it got stuck at that line, until I changed
$sth=$dbh->prepare($SQL) to
$sth=$dbh->prepare($sql)

-Josh http://www.datera.com

Reply With Quote
  #9  
Old March 21st, 2000, 07:32 PM
bydavid bydavid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: USA
Posts: 67 bydavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
i tried that , but i still have the same problem.

i have switched to teh mysql module and i got
results the frist time. what is the difference, where can i find information about all the functions included in mysql module.

Reply With Quote
  #10  
Old March 27th, 2000, 09:56 AM
12338323 12338323 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: eugene, or, us
Posts: 8 12338323 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to 12338323
You need to double quote the prepare statement, otherwise Mysql interprets the information inside of the parentheses literally. For example:
prepare ("select * from $table where $item = ?)
This will pass the query statement to mysql with the values of the variables inserted in the command line. If you don't double quote this statement, then the command that mysql would see would be: select * from $table where $item = ?. This won't work as mysql has no idea what the values of $table and $item are.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Perl and DBI


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway