Welcome to the Mobile Bridge Plex Server
host=$dbhost;
$this->user=$dbuser;
$this->pass=$dbpass;
$this->name=$dbname;
}
/* Okay, here is a method to setup the connection. */
function setup_connection()
{
/* Create connection and store it in $con */
$time=$_SERVER['REQUEST_TIME'];
echo "Hello $time $dbuser
";
echo "Calling mysqli_connect
";
/* Create a new object of type mysqli, its
* constructor wants several parameters when
* the object is created, the server, the user,
* and the user password. If you look at the
* documentation there are a lot more
* parameters it can take during initialization
* but I just did the basic three.
*/
$con=new mysqli($this->host, $this->user,
$this->pass);
echo "Called mysqli_connect
";
/* Check the field connect_errno of the object
* to see if the database returned an error, if
* it did error out of the function/kill the
* script.
*/
if ($con->connect_errno)
die("Connection error: " . $con->connect_errno ." ". $con->connect_error);
echo "Successfully called mysqli_connect
";
/* Select known database "mysql" */
/* The following sends a message to the mysqli
* object to select a new database, which is
* identified as dbname. The message returns
* success/failure. More information on it can
* be found on the mysqli API page. I used the
* one found at w3schools. If error, end
* function/kill the script.
*/
if (!$con->select_db($this->name))
die("Selection error: " . $con->error);
echo "Successfully called mysqli_select_db
";
$this->con = $con;
return $con;
}
/* Okay, here is a method called issue_query.
* It accepts an SQL query as a string,
*
*/
function issue_query($sql)
{
/* If connection is lost? Reissue connection */
if (!$this->con)
$this->setup_connection;
/* Issue query on Database using user table -
* Store in result
*/
/* Send the message query to the mysqli object,
* this issues the MYSQL command found in the
* $sql string.
*/
$res=$this->con->query($sql);
if (!$res) { /* Reconnect and retry */
$this->setup_connection();
$res = $this->con->query($sql);
}
if (!res)
die ("Error issuing query" . $con->error());
return $res;
}
function select_username($username)
{
$this->username = $username;
}
}
/* Okay we have the class database defined,
* let's actual assign some memory to it and
* start using it. When we create an instance
* of a class, it is called an object.
* In this case the object is a very simple
* class with just public fields.
* So it behaves as a structure.
*/
/* $dbase = new database("localhost", "root", "", "mysql"); */
$dbase = new database($global->dbhost, $global->dbuser, $global->dbpass,
$global->dbname);
$dbase->setup_connection();
/* Send the message issue_query with an SQL query. */
$result=$dbase->issue_query("SELECT * FROM user;");
/* Okay, issue_query returns the result of
* mysql_query, which if successful is a
* collection of entries. To pick
* the first entry, you call fetch_assoc(),
* when you are done processing that entry,
* to pick the next you call fetch_assoc().
* Each row is an array of fields.
* Since array's in PHP are just mappings,
* the field names are the keys and
* the values are the values.
*/
while ($row = $result->fetch_assoc()) {
foreach ($row as $value)
echo "$value ";
echo "
";
}
/* Change what the query is and do it again */
/* Okay, issue_query returns the result of
* mysql_query, which if successful is a
* collection of entries. To pick the first
* entry, you call fetch_assoc(), when you are
* done processing that entry, to pick the next
* you call fetch_assoc(). Each row is an array
* of fields. Since array's in PHP are just
* mappings, the field names are the keys and
* the values are the values.
*/
/* old
$sql2="SELECT User,Password FROM user WHERE User='debian-sys-maint';";
$result = $dbase->issue_query("SELECT User,Password FROM user WHERE User='debian-sys-maint';");
*/
$sql2="SELECT `username`,`password` FROM user WHERE `uid`='123456789';";
$result = $dbase->issue_query($sql2);
$row = $result->fetch_assoc();
$username = array_keys($row)[0];
$password = array_keys($row)[1];
echo "DAK $username/$password
";
$username = $row['User'];
$password = $row['Password'];
echo "DAK $username/$password
";
?>
Wonder what will happen !!!