PDA

View Full Version : NetConnection.Call.BadVersion errors


bianster
07-14-2004, 10:12 AM
I tried to run the PHP script below with AMFPHP and Flash MX 2004 Pro but I would receive NetConnection.Call.BadVersion erros in the debugger. The classes are separated into files and there's no parsing or syntax errors because I have tested it directly from the web browser previously.

config.inc.php
<?php
$DSN = "Records";
$HOST = "localhost";
$USER = "";
$PASSWORD = "";

define("DSN", $DSN);
define("USER", $USER);
define("PASSWORD", $PASSWORD);
?>


<?PHP
include_once("../config.inc.php");
/************************************************
/ Purpose: This class provides for database
/ function abstraction.
/ Usage: Replace the DB specific functions to
/ the target database's
/ Author: Douglas Tan ([email protected])
/ Version: 0.1
************************************************/

class sql{
var $conn;
function sql(){
$this->conn = @odbc_connect(DSN, USER, PASSWORD);
if($this->conn){
return $this->conn;
}
else{
//die("Database is offline\n".odbc_errormsg());
return false;
}
}
function query($query = null){
return odbc_exec($this->conn, $query);
}
function getResultRow($resultId){
return odbc_fetch_row($resultId);
}
function getRowData($resultId, $field){
return odbc_result($resultId, $field);
}
function getRowNum($resultId){
return odbc_num_rows($resultId);
}
function rollback(){
return odbc_rollback($this->conn);
}
function getError(){
return odbc_error();
}
}
?>


<?PHP
include ("./sql.php");
/************************************************** *************
/ Purpose: This class authenticates the client
/ login against database records
/ Methods: login()
/ >> takes in the flash client's login credentials
/ and checks it against the table (Users)
/ the target database's
/ Author: Douglas Tan ([email protected])
/ Version: 0.1
************************************************** ****************/
class User{
function User(){
$this->methodTable = array(
"modifyText" => array(
"description" => "Test Function",
"access" => "remote",
"arguments" => array("args1"),
"returns" => "array"
),
"verifyUser" => array(
"description" => "Verifies the client's login credentials against the database records",
"access" => "remote",
"arguments" => array("args1"),
"returns" => "array"
),
"insertUser" => array(
"description" => "Inserts a new user for login",
"access" => "remote",
"arguments" => array("args1"),
"returns" => "boolean"
)
);
}
function modifyText($text){
$word = array();
$word["txt"] = $text;
return $word;
}
function verifyUser($user){
$login = array();
$ID = addslashes($user["UID"]);
$password = addslashes($user["Password"]);
$query = "select name, accessLevel from Users where ID = '".$ID."' and password = '".$password."'";
$conn = new sql();
$result = $conn->query($query);
if($result){
if($conn->getResultRow($result)){
$login["userName"] = $conn->getRowData($result, 1);
$login["accessLevel"] = $conn->getRowData($result, 2);
$login["failed"] = false;
}
else{
$login["failed"] = false;
}
}
else{
$login["failed"] = false;
}
return $login;
}
function insertUser($user){
$values[] = "'".$user["UID"]."'";
$values[] = "'".$user["Password"]."'";
$values[] = "'".$$user["Name"]."'";
$values[] = $user["accessLevel"];
$cSValues = implode(",", $values);
$query = "insert into Users (ID, password, name, accessLevel) values ($cSValues)";
$conn = new sql();
$result = $conn->query($query);
if($result){
return true;
}
else{
return false;
}
}
}
?>


the thing is i'm able to call modifyText() from another class just fine

<?php
class Test{
function Test(){
$this->methodTable = array(
"modifyText" => array(
"description" => "Test Function",
"access" => "remote",
"arguments" => array("args1"),
"returns" => "array"
)
);
}
function modifyText($text){
$word = array();
$word["txt"] = $text;
return $word;
}
}
?>


After staring at the code for hours, I still can't find where the problem lies... :confused:

bianster
07-14-2004, 02:24 PM
i've sort of managed to narrow down the source of the problem.

here's a stripped-down version of the earlier scripts, when i try to perform the SQL query using the odbc functions directly in user.php, it works out beautifully. However, after i modify it to use sql.php's database methods, the NetConnection.Call.BadVersion errors return.
Can't i implement database abstraction for AMFPHP?

//error_reporting(0);
class sql{
var $conn;
function sql(){
$this->conn = @odbc_connect("Records", "", "");
if($this->conn){
return $this->conn;
}
else{
return false;
}
}
function query($query){
return odbc_exec($this->conn, $query);
}
function getResultRow($resultId){
return odbc_fetch_row($resultId);
}
function getRowData($resultId, $field){
return odbc_result($resultId, $field);
}
}
?>


<?php
include ("./sql.php");
class user{
function user(){
$this->methodTable = array(
"verifyUser" => array(
"description" => "Verifies login credentials",
"access" => "remote",
"arguments" => array("args1")
)
);
}
function verifyUser($user){
$login = array();
$ID = addslashes($user["UID"]);
$password = addslashes($user["Password"]);
$query = "select name, accessLevel from Users where ID = '".$ID."' and password = '".$password."'";
$conn = new sql();
if(!$conn){
return $login["failed"] = true;
}
$result = $conn->query($query);
if($result){
if($conn->getResultRow($result)){
$login["userName"] = $conn->getRowData($result, 1);
$login["accessLevel"] = $conn->getRowData($result, 2);
$login["failed"] = false;
}
else{
$login["failed"] = true;
}
}
else{
$login["failed"] = true;
}
return $login;
}
}
?>

bianster
07-14-2004, 02:35 PM
Yes!! I found the solution on the FlashDB forums, it turns out that the included classes need to be included IN the function that makes use of them....doesnt make any sense to me, but hey, it works!

here's the url if anyone's interested => http://www.flash-db.com/Board/index.php?board=24;action=display;threadid=7039