Hello,
Im trying to make a simple flash site which gets its main content from a database. I try to use the database class to connect mx and Mysql (found in exellent beginner/advanced book php5 for flash)
http://www.friendsofed.com/books/1590594665/index.html
Anyway, this is the database.php
<?php
class Database {
var $dbHost;
var $dbUser;
var $dbPass;
var $dbName;
var $flash;
var $dbLink;
var $result;
var $resultObj;
function Database($dbHost, $dbUser, $dbPass, $dbName, $flash=1){
$this->host = $dbHost;
$this->user = $dbUser;
$this->pwd = $dbPass;
$this->dbName = $dbName;
$this->flash = $flash;
$this->connect();
}
// Connect to the mySQL Server and Select the database
function connect() {
$this->dbLink = @mysql_pconnect($this->host, $this->user, $this->pwd);
if (!$this->dbLink) {
$error = 'Couldn\'t connect to mySQL Server';
echo $this->flash ? 'error='.urlencode($error) : $error;
exit();
}
if (!@mysql_select_db($this->dbName, $this->dbLink)) {
$error = 'Couldn\'t open Database: '. $this->dbName;
echo $this->flash ? 'error='.urlencode($error) : $error;
exit();
}
return $this->dbLink;
}
// Execute an SQL query
function query($query) {
$this->result = @mysql_query($query, $this->dbLink);
if (!$this->result) {
$error = 'MySQL Error: ' . mysql_error();
echo $this->flash ? 'error='.urlencode($error) : $error;
exit();
}
// store result in new object to emulate mysqli OO interface
$this->resultObj = new MyResult($this->result);
return $this->resultObj;
}
function close(){
// Close MySQL Connection
@mysql_close($this->dbLink);
}
}
class MyResult {
var $theResult;
var $num_rows;
function MyResult(&$r) {
if (is_bool($r)) {
$this->num_rows = 0;
}
else {
$this->theResult = $r;
// get number of records found
$this->num_rows = @mysql_num_rows($r);
}
}
// fetch associative array of result (works on one row at a time)
function fetch_assoc() {
$newRow = @mysql_fetch_assoc($this->theResult);
return $newRow;
}
}
?>
and here is my returnData.php script
<?php
require_once('database.php');
$db = new Database('localhost', 'username', 'password', 'database');
$theRow=$_POST['row'];
$sql="SELECT * FROM siteData WHERE section_id='$theRow'";
$result= $db->query($sql);
$row=@mysql_fetch_array($result);
$theText=urlencode($row['section_text']);
$theImage=urlencode($row['section_image']);
echo "&theText=$theText&theImage=$theImage";
$db->close();
?>
The idea is that a table is searched by section_id and this returns text and a link to a .jpg file that should load up. (both of them dont!)
Somehow the script ‘works’ but the sql query returns 0 and so I dont see data appearing in the swf.
Any suggestions are welcome, thanks ken