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:
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: