Hi all
I'm trying to set my mysqli connection to my database as outlined in http://php.net/manual/en/mysqli.quickstart.connections.php , with one difference - I'm trying to put my connection parameters in an include file outside of my root folder, to try to secure my DB password.
$mysqli = new mysqli("DBServer", "DBUsername", "DBPassword", "DBName"); //set connection params
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
exit();
Now, with my query object, I can confirm that the connection is established, and the connection file is included when I launch my class_lib file, but, when I try to use the connection object, it returns "Call to a member function query() on a non-object in filename on line 21"
The code for my object is as follows:
class siteConfig {
protected $results = array();
public function set_siteConfig() {
$res = $mysqli->query($mysqli,"SELECT status FROM `site-config`");
$this->results = $res->fetch_assoc();
$mysqli->close();
}
public function get_siteConfig() {
return $this->results;
}
}
The error message is telling me that the error is in the line "$res = $mysqli->query($mysqli,"SELECT * FROM site-config
");"
How can I correctly implement my database connection, while, at the same time, keeping my database credentials secure?
Thanks for any suggestions you guys might have!
-Jay