Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable as the DataBase name?

Status
Not open for further replies.

GroundZero

Programmer
Feb 1, 2001
28
CA
I have a problem here: php won't take a variable as the database name. can anyone help figure this one please.
Also I posted my whole code so if you see any mistake in it let me know.

//this is desidned to be used with flash to be able to do
//any interaction possible between flash and any BD
//supported by php
//Yan Brais, the_whiteknight_99@yahoo.com

<?php

switch($DBtype)
{
case &quot;odbc&quot;:

switch($DBaction)
{
case &quot;read&quot;:
if ($DBselect=&quot;all&quot;)
{
$DBselect=&quot;*&quot;;
}

//connect to database
$connect = odbc_connect($DBname, &quot;&quot;, &quot;&quot;) or die(&quot;couldn't connect.&quot;);

//query the user table for room and message
$query = &quot;SELECT $DBselect FROM $DBtable&quot;;

if ($DBwhere!=none)
{
$query .= &quot;WHERE $DBwhere=$DBfield&quot;;
}

//perform the query
$result = odbc_do($connect, $query);

$NbFields=odbc_num_fields($result);
$i=1;
$j=1;

while (odbc_fetch_row($result))
{

for ($j=1;$j<=$NbField;$j++)
{
$fieldName=odbc_field_name($result,$j);
$letterRef=urlencode(odbc_result($result,$j));
print(&quot;$fieldName$i=$letterRef&&quot;);
}
$i++;
}

$i=$i;
print(&quot;ok=1&&quot;);
print(&quot;maxi=$i&&quot;);

//disconnect from database
odbc_close($connect);

break;

case &quot;write&quot;:
//connect to database
$connect = odbc_connect(&quot;$DBname&quot;, &quot;&quot;, &quot;&quot;) or die(&quot;couldn't connect.&quot;);

//query the user table for room and message
$query=&quot;INSERT INTO $DBtable ($DBwhere)&quot;;
$query .=&quot;VALUES ('$DBvalues')&quot;;

//perform the query
$result = odbc_do($connect, $query);

print(&quot;&pen=1&&quot;);

//disconnect from database
odbc_close($connect);

break;


case &quot;update&quot;:
//connect to database
$connect = odbc_connect(&quot;$DBname&quot;, &quot;&quot;, &quot;&quot;) or die(&quot;couldn't connect.&quot;);

$connection=odbc_do($connect);
$num=odbc_num_fields($connection);
for ($i=1;$i<=$num;$i++)
{
$fieldNameArray[$i]=odbc_field_name($connection,$i);
}

$query=&quot;UPDATE $DBtable&quot;;

for ($j=1;$j<=$num;$j++)
{
//query the user table for room and message
$query .=&quot;SET $fieldNameArray[$wichone]= $DBvalues&quot;;
}

if ($DBwhere!=none)
{
$query .= &quot;WHERE $DBwhere=$DBfield&quot;;
}
odbc_close ($connect);

$result=odbc_do($connect,$result);
print (&quot;&updated=1&&quot;);

odbc_close($connect);

break;

case &quot;delete&quot;:
//connect to database
$connect = odbc_connect(&quot;$DBname&quot;, &quot;&quot;, &quot;&quot;) or die(&quot;couldn't connect.&quot;);

$query=&quot;DELETE FROM $DBtable&quot;;

if ($DBwhere!=none)
{
$query .= &quot;WHERE $DBwhere=$DBfield&quot;;
}

$result=odbc_do($connect,$query);

print (&quot;&erased=1&&quot;);

odbc_close($connect);
break;


case &quot;default&quot;:
print (&quot;&connectFailed&quot;);
break;
}
break;


}
Your soul is imperfect
Life is difficult...

Now guess why we're here
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top