这是我的代码:
include 'conn.php';
$conn = new Connection();
$query = 'SELECT EmailVerified, Blocked FROM users WHERE Email = ? AND SLA = ? AND `Password` = ?';
$stmt = $conn->mysqli->prepare($query);
$stmt->bind_param('sss', $_POST['EmailID'], $_POST['SLA'], $_POST['Password']);
$stmt->execute();
$result = $stmt->get_result();
Run Code Online (Sandbox Code Playgroud)
我在最后一行得到错误:调用未定义的方法mysqli_stmt :: get_result()
这是conn.php的代码:
define('SERVER', 'localhost');
define('USER', 'root');
define('PASS', 'xxxx');
define('DB', 'xxxx');
class Connection{
/**
* @var Resource
*/
var $mysqli = null;
function __construct(){
try{
if(!$this->mysqli){
$this->mysqli = new MySQLi(SERVER, USER, PASS, DB);
if(!$this->mysqli)
throw new Exception('Could not create connection using …Run Code Online (Sandbox Code Playgroud) 我已经在网上搜索了一个很好的例子,但我找不到任何东西.
我试图扩展mysqli类来创建一个帮助类,它将抽象出一些复杂性.我想要完成的主要事情之一是使用准备好的陈述.
我真的不知道从哪里开始,或者如何在一个类中正确处理输入和输出.另一个问题是,在使用预准备语句时,我无法将数据作为数组输出.
我真的可以用一个简单的例子来指出我正确的方向.
谢谢!
任何人都可以帮助我如何在PHP上创建动态bind_result.我的查询字段不知道自动态创建以来有多少字段(例如,根据日期范围创建年份字段).下面是我的脚本,并突出显示问题在哪里.
public function getMarketingReports($datefrom,$dateto)
{
$yearfrom = date("Y", strtotime($datefrom));
$yearto = date("Y", strtotime($dateto));
//create year fields
$concatYear = "";
for($year=$yearfrom;$year<=$yearto;$year++){
$concatYear .= "SUM(IF(c.datecreated='".$year."',IF(LOWER(c.fullTimeEployeeType)='basic hour rate', c.fullTimeEployeeTypeAmount*2080 , c.fullTimeEployeeTypeAmount),0)) ".$year.",";
}
$reportdata = array();
$db = Connection::Open();
$stmt = $db->stmt_init();
if($stmt->prepare("SELECT p.Code `PositionCode`,
p.name `PositionName`,
l.value `Location`,
".$concatYear."
SUM(b.field205) `TotalEmployees`
FROM c1 c
INNER JOIN b1 b
ON c.registrationid=b.id
INNER JOIN positions p
ON c.positionid=p.id
INNER JOIN lookupvalues l
ON c.location=l.id
WHERE c.`status`!=2
AND c.datecreated BETWEEN ? AND ? …Run Code Online (Sandbox Code Playgroud)