duanfengtuo6012 2015-03-11 12:10
浏览 66
已采纳

在非对象上调用成员函数bindValue()[duplicate]

This question already has an answer here:

So I'm trying to create a prepared insert statement to a database for a web app. For the registration system, I'm feeding in values using post, then redirecting to a webpage to do the processing. However, I keep getting the error 'Call to a member function bindValue() on a non-object in /path/to/file.php on line 18, the first reference to bindValue(). The code is:

<?php

 session_start();

 require "database.php";
 $db = new Database("bills.db");

 $admin_password = $_POST['admin_password'];
 $admin_email = $_POST['admin'];
 $salt = sha1(time());
 $group_name = $_POST['group_name'];
 $group_password = $_POST['password'];

 $admin_hash = sha1($salt."--".$admin_password);
 $group_hash = sha1($salt."--".$group_password);

$stmt = $db->prepare("INSERT INTO billgroup VALUES (NULL, :adminemail, :adminpassword_hash, :groupname, :password_hash, :salt)");
$stmt->bindValue(':adminemail', $admin_email, SQLITE3_TEXT);
$stmt->bindValue(':adminpassword_hash', $admin_hash, SQLITE3_TEXT);
$stmt->bindValue(':groupname', $group_name, SQLITE3_TEXT);
$stmt->bindValue(':password_hash', $group_hash, SQLITE3_TEXT);
$stmt->bindValue(':salt', $salt, SQLITE3_TEXT);
$results = $stmt->execute();




 $stmt = $db->prepare("SELECT * FROM billgroup WHERE adminemail = :adminemail");
 $stmt->bindValue(':adminemail', $admin_email, SQLITE3_TEXT);
 $users = $stmt->execute();
 $user = $users->fetchArray();
...
</div>
  • 写回答

1条回答 默认 最新

  • dongniaocheng3773 2015-03-13 19:12
    关注

    You want connect to a sqlite database but you have:

    $db = new Database("bills.db");
    

    You must know that you must have something like this:

    $db = new PDO('sqlite:bills.db');
    

    And change in all the bindValue calls the SQLITE3_TEXT to PDO::PARAM_STR like this:

    $stmt->bindValue(':adminemail', $admin_email, SQLITE3_TEXT);
    

    to:

    $stmt->bindValue(':adminemail', $admin_email, PDO::PARAM_STR);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵