【发布时间】:2014-06-09 06:46:34
【问题描述】:
我用过这个查询:
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
在phpadmin中没问题,但在代码中返回false,可能是什么原因?
更新
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;
}
这里是db类的来源,我这样称呼它:
$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
这里有什么想法吗?
我的配置:
<?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';
}
我的配置文件
【问题讨论】:
-
您是否检查过查询的错误结果?如果是这样,它在哪里和说什么?如果没有,我会尝试(并确保
name不是两个表中的列名。 -
@JeremyMiller 我试过 var dump,所有属性都有空值,无法弄清楚发生了什么,因为查询有效(在 phpmyadmin sql 提示符中检查)连接很稳定
-
你能告诉我们表格的结构吗?
-
我认为在编辑这个问题的过程中,PHP部分被意外删除了。
-
@JeremyMiller 他实现了自己的数据库类,代码都在问题中。