I am busy creating a custom CMS that also uses a custom template engine.
But i am coding with MySQL but I know i have to change to MySQLI.
Now the problem is that I can’t get it to work the way it is supposed to.
I created a function connect and it looks like this :
/*
@function connect : This function will be used to establich a connection with the database.
*/
public function connect() {
// Set up connection details for the site
$con = mysql_connect($this->host, $this->username, $this->password);
if (!$con) {
die("ShadowCMS could not connect to the database: " . mysql_error());
}
// Set up the database
$db_select = mysql_select_db($this->db, $con);
if(!$db_select) {
die("ShadowCMS could not select a database: " . mysql_error());
}
}
Now when i change it to this :
/* @function connect : This function will be used to establich a connection with the database.
*/
public function connect() {
// Set up connection details for the site
$con = mysqli_connect($this->host, $this->username, $this->password, $this->db);
if (!$con) {
die("ShadowCMS could not connect to the database: " . mysqli_error());
}
}
It will always give back the error : database not selected.
The error is pretty clear. You forgot to select your database (add the following code).
mysqli_select_db($this->db, $con);
Still doesn’t work…
now i get this error :
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\projecten\shadowCMS_beta\shadow\classes\shadow.php on line 105
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\projecten\shadowCMS_beta\shadow\classes\shadow.php on line 107
ShadowCMS could not select a database:
The error is pretty clear. You forgot to select your database (add the following code).
mysqli_select_db($this->db, $con);
Still doesn’t work…
now i get this error :
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\projecten\shadowCMS_beta\shadow\classes\shadow.php on line 105
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\projecten\shadowCMS_beta\shadow\classes\shadow.php on line 107
ShadowCMS could not select a database:
I copied your existing code and didn't go through it. $con and $this->db should be switched.