Reputation: 13
I've used this query:
SELECT * FROM sillaru_users AS users
JOIN sillaru_users_data AS users_data
ON users.id = users_data.user_id
WHERE name = 'user_package_id' AND users.id = 2
in phpadmin its ok, but in the code it returns false, what can be the reason?
UPDATE
public function __construct($data)
{
foreach($data as $key => $value)
{
$this->$key = $value;
}
$this->conn = mysqli_connect($this->host, $this->username, $this->password, $this->db);
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$this->conn->set_charset("utf8");
}
public function query($query)
{
$this->result = $this->conn->query($query);
return $this;
}
public function row()
{
if($this->result)
{
$row = mysqli_fetch_assoc($this->result);
mysqli_free_result($this->result);
}
else
{
$row = false;
}
return $row;
}
HERE is the source of the db class, I call it like this:
$node = $this->db->query("SELECT * FROM ".Config::$prefix."users AS users JOIN ".Config::$prefix,"users_data AS users_data ON users.id = users_data.user_id WHERE name = 'user_package_id' AND users.id = {$id}")->row();
var_dump($node); //boolean false
here it is any ideas?
My Config:
<?php
class Config
{
public static $charset = 'UTF-8';
public static $prefix = 'sillaru_';
public static $maxUsersPerLevel = 3;
public static $db = array(
'localhost' => 'localhost',
'prefix' => 'sillaru_',
'db' => 'sillaru',
'username' => 'root',
'password' => ''
);
public static $currentApplication = 'sillaru';
}
my config file
Upvotes: 0
Views: 127
Reputation: 1561
error seems to be here on the line below near .Config::$prefix , -- where comma have to separated with dot.
$node = $this->db->query("SELECT * FROM ".Config::$prefix."users AS users JOIN ".Config::$prefix,"users_data AS users_data ON users.id = users_data.user_id WHERE name = 'user_package_id' AND users.id = {$id}")->row();
var_dump($node);
replace by below line
$node = $this->db->query("SELECT * FROM ".Config::$prefix."users AS users JOIN ".Config::$prefix."users_data AS users_data ON users.id = users_data.user_id WHERE name = 'user_package_id' AND users.id = {$id}")->row();
Upvotes: 3
Reputation: 635
Use alias.* in place of *
SELECT users.* FROM sillaru_users AS users
JOIN sillaru_users_data AS users_data
ON users.id = users_data.user_id
WHERE name = 'user_package_id' AND users.id = 2
Upvotes: 0