I'm trying to select a single value from mysql - but however it does not work:
public function doStuff($posted_name){
$result = mysql_query("SELECT id FROM people WHERE people_name = $posted_name");
$singleValue = mysql_fetch_object($result);
}
posted_name, people_name is TEXT, id is INT
I am posting a $posted_name , this I let compare with column people_name from table people, and selecting the column "id" ...
this id i want to store as value , here I tried to store it in $singleValue... but however it does not work - is there any mistake?
Solved: see comments
EDIT:
I changed some code to mysqli for testing- but now I have some error:
my code looks like:
private $db;
// constructor
function __construct() {
include_once './db_connect.php';
// connecting to database
$db = new DB_Connect();
$this->db = $db->connect();
}
. . . . .
$result = this->db->query("INSERT INTO.....
The error appears for the above line ... Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR)...
what I am doing wrong
my db_connect.php
class DB_CONNECT {
private $db;
// constructor
function __construct() {
// connecting to database
$this->connect();
}
/**
* Function to connect with database
*/
function connect() {
// import database db variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$this->db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Selecing database
// returing connection cursor
return $this->db;
}
}