GroundZero
Programmer
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 "odbc":
switch($DBaction)
{
case "read":
if ($DBselect="all"
{
$DBselect="*";
}
//connect to database
$connect = odbc_connect($DBname, "", ""
or die("couldn't connect."
;
//query the user table for room and message
$query = "SELECT $DBselect FROM $DBtable";
if ($DBwhere!=none)
{
$query .= "WHERE $DBwhere=$DBfield";
}
//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("$fieldName$i=$letterRef&"
;
}
$i++;
}
$i=$i;
print("ok=1&"
;
print("maxi=$i&"
;
//disconnect from database
odbc_close($connect);
break;
case "write":
//connect to database
$connect = odbc_connect("$DBname", "", ""
or die("couldn't connect."
;
//query the user table for room and message
$query="INSERT INTO $DBtable ($DBwhere)";
$query .="VALUES ('$DBvalues')";
//perform the query
$result = odbc_do($connect, $query);
print("&pen=1&"
;
//disconnect from database
odbc_close($connect);
break;
case "update":
//connect to database
$connect = odbc_connect("$DBname", "", ""
or die("couldn't connect."
;
$connection=odbc_do($connect);
$num=odbc_num_fields($connection);
for ($i=1;$i<=$num;$i++)
{
$fieldNameArray[$i]=odbc_field_name($connection,$i);
}
$query="UPDATE $DBtable";
for ($j=1;$j<=$num;$j++)
{
//query the user table for room and message
$query .="SET $fieldNameArray[$wichone]= $DBvalues";
}
if ($DBwhere!=none)
{
$query .= "WHERE $DBwhere=$DBfield";
}
odbc_close ($connect);
$result=odbc_do($connect,$result);
print ("&updated=1&"
;
odbc_close($connect);
break;
case "delete":
//connect to database
$connect = odbc_connect("$DBname", "", ""
or die("couldn't connect."
;
$query="DELETE FROM $DBtable";
if ($DBwhere!=none)
{
$query .= "WHERE $DBwhere=$DBfield";
}
$result=odbc_do($connect,$query);
print ("&erased=1&"
;
odbc_close($connect);
break;
case "default":
print ("&connectFailed"
;
break;
}
break;
}
Your soul is imperfect
Life is difficult...
Now guess why we're here
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 "odbc":
switch($DBaction)
{
case "read":
if ($DBselect="all"
{
$DBselect="*";
}
//connect to database
$connect = odbc_connect($DBname, "", ""
//query the user table for room and message
$query = "SELECT $DBselect FROM $DBtable";
if ($DBwhere!=none)
{
$query .= "WHERE $DBwhere=$DBfield";
}
//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("$fieldName$i=$letterRef&"
}
$i++;
}
$i=$i;
print("ok=1&"
print("maxi=$i&"
//disconnect from database
odbc_close($connect);
break;
case "write":
//connect to database
$connect = odbc_connect("$DBname", "", ""
//query the user table for room and message
$query="INSERT INTO $DBtable ($DBwhere)";
$query .="VALUES ('$DBvalues')";
//perform the query
$result = odbc_do($connect, $query);
print("&pen=1&"
//disconnect from database
odbc_close($connect);
break;
case "update":
//connect to database
$connect = odbc_connect("$DBname", "", ""
$connection=odbc_do($connect);
$num=odbc_num_fields($connection);
for ($i=1;$i<=$num;$i++)
{
$fieldNameArray[$i]=odbc_field_name($connection,$i);
}
$query="UPDATE $DBtable";
for ($j=1;$j<=$num;$j++)
{
//query the user table for room and message
$query .="SET $fieldNameArray[$wichone]= $DBvalues";
}
if ($DBwhere!=none)
{
$query .= "WHERE $DBwhere=$DBfield";
}
odbc_close ($connect);
$result=odbc_do($connect,$result);
print ("&updated=1&"
odbc_close($connect);
break;
case "delete":
//connect to database
$connect = odbc_connect("$DBname", "", ""
$query="DELETE FROM $DBtable";
if ($DBwhere!=none)
{
$query .= "WHERE $DBwhere=$DBfield";
}
$result=odbc_do($connect,$query);
print ("&erased=1&"
odbc_close($connect);
break;
case "default":
print ("&connectFailed"
break;
}
break;
}
Your soul is imperfect
Life is difficult...
Now guess why we're here