I'm trying to set up a class using PHP that has a constructor that will create a connection to a mySQL server and I'm having trouble doing so.
If the table doesn't exist in the database, it will also do the necessary commands to create the table.
So far I have the following code:
class PHPClass{ // Variables var $SQLHost = "localhost"; var $SQLDatabase = "SQL_DB"; var $SQLUser = "username"; var $SQLPass = "password"; // Connection var $Connection; function __construct() { $Connection = new MySQLi( $SQLHost, $SQLUser, $SQLPass, $SQLDatabase ); // Check if the table exists $SQLQuery = "SELECT * FROM table_data"; $Query = @mysqli_query( $Connection, $SQLQuery ); // If it doesn't exist, create the table and fill it with data. if ( !$query ) { // Create the "hitcounter" table $SQLQuery = "CREATE TABLE table_data ( id SMALLINT NOT NULL PRIMARY KEY, data SMALLINT NOT NULL )"; // Execute Query @mysqli_query( $Connection, $SQLQuery ); // Create the "hitcounter" table $SQLQuery = "INSERT INTO table_data VALUES (1,1);"; // Execute Query @mysqli_query( $Connection, $SQLQuery ); } }}