OOP/Classes and Databases
Posted: Thu Mar 27, 2008 8:13 pm
First off, this is my first post here. I am a student in a university on Vancouver Island.
Hi.
I am having a dickens of a time with my code. I have watered it down, to just the concept now. Can anyone out there please help. Thanks in advance. Kyle Corey
This first Code is my Class page. it is saved as con_test.php
This is the page that will access the function setDatabase, and in my full program it is suppose to select the database and enter a new user into a table. Again this is just the nuts and bolts.
Any help, suggestions or links would be very helpful....
Cheers Kyle Corey
http://www.kylecorey.ca
Hi.
I am having a dickens of a time with my code. I have watered it down, to just the concept now. Can anyone out there please help. Thanks in advance. Kyle Corey
This first Code is my Class page. it is saved as con_test.php
Code: Select all
<?php
class Test {
function __construct(){
$this->dbConnect = @new mysqli("localhost", "root", "******"); //not the actual password
if (mysqli_connect_errno()) {
die("<p>Unable to connect to the database server!!</p>");
} else echo "<p>Connected to database server</p>";
}
function __destruct() {
}
public function setDatabase($database) {
$this->database = $database;
$this->dbConnect->query($database) or die("<p>Unable to select the database!!");
}
}
?>Code: Select all
<?php
require_once("con_test.php");
session_start();
$test = new Test();
$test->setDatabase('coreyk_bankdb') or die("doh");
?>Cheers Kyle Corey
http://www.kylecorey.ca