在我的本地/开发环境中,MySQLi查询执行正常.但是,当我在我的Web主机环境中上传它时,我收到此错误:
致命错误:在...中的非对象上调用成员函数bind_param()
这是代码:
global $mysqli;
$stmt = $mysqli->prepare("SELECT id, description FROM tbl_page_answer_category WHERE cur_own_id = ?");
$stmt->bind_param('i', $cur_id);
$stmt->execute();
$stmt->bind_result($uid, $desc);
Run Code Online (Sandbox Code Playgroud)
为了检查我的查询,我试图通过控制面板phpMyAdmin执行查询,结果是OK.
我正在尝试在内容表中插入值.如果我在VALUES中没有PHP变量,它可以正常工作.当我将变量$type放在VALUES中时,这不起作用.我究竟做错了什么?
$type = 'testing';
mysql_query("INSERT INTO contents (type, reporter, description)
VALUES($type, 'john', 'whatever')");
Run Code Online (Sandbox Code Playgroud) PHP 手册mysqli_connect()建议检查返回值并在屏幕上显示错误消息。
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
Run Code Online (Sandbox Code Playgroud)
同样,对于 OOP 样式的构造函数,建议这样做:
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
Run Code Online (Sandbox Code Playgroud)
Stack Overflow 上的一些用户甚至使用了mysqli_error($conn)这样的代码:
$conn = mysqli_connect('localhost', 'a', 'a');
if (!$con) {
die('Could not connect: …Run Code Online (Sandbox Code Playgroud) 如果我使用这样的代码:
$update_result = mysqli_query( $link , $sql_update_login ) or die ('Unable to execute query. '. mysqli_error($link));
Run Code Online (Sandbox Code Playgroud)
它是否必须死亡或者您之后可以提出不同的查询?就像将错误日志写入另一个表的预定函数一样?如:
$update_result = mysqli_query( $link , $sql_update_login ) or function('$query, $error);
Run Code Online (Sandbox Code Playgroud)
'或'之后的其他选项有哪些?我没有在文档中找到它,任何线索都表示赞赏.
此mysqli_query命令导致以下错误
mysqli_query("INSERT INTO `counter`.`hits` (`page_hits`) VALUES ('".$hits."')");
Run Code Online (Sandbox Code Playgroud)
"警告:mysqli_query()需要至少2个参数,1"
此错误消息的含义是什么,以及如何修复?
嗨我有一个70/80字段表单,我需要插入到表中,所以而不是手动创建一个巨大的插入语句我首先在我的数据库中创建一个表从表单中的输入的名称这里是我的代码用于创建/更改表
function createTable($array, $memberMysqli)
{
foreach ($array as $key => $value)
{
//echo "<p>Key: ".$key." => Value: ".$value . "</p>";
$query = "ALTER TABLE questionnaire ADD ".$key." text";
if($stmt = $memberMysqli->prepare($query))
{
$success = $stmt->execute();
}
}
echo "<h1>Array count: ". count($array) ."</h1>" ;
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,并改变了我想要的表格.现在要插入表单值来执行此操作,我执行基本的一个字段插入存储行的id,然后循环所有更新该行的post变量.这是我的代码:
$stmt = $memberMysqli->prepare("INSERT INTO questionnaire(userid) VALUES (?)");
$stmt->bind_param('s', $_POST['userid']);
$stmt->execute();
$rowid = $stmt->insert_id;
$stmt->close();
$memberMysqli->autocommit(FALSE);
function updateColumn($memberMysqli, $query, $uid, $value)
{
if ($value)
{
$stmt = $memberMysqli->prepare($query);
//Throws bind param error here
$stmt->bind_param("ss", $value, …Run Code Online (Sandbox Code Playgroud) 我试图使用下面的php预处理语句在mysql表中插入一行,但代码总是传递语句并移动到echo"failed".以下代码中缺少什么?
(我的数据库有额外的列,但我没有添加它,因为我不想在里面插入值(其中一列是自动增量))
<?php
$ActivityDate = $_POST["ActivitytDate"];
$CoreSite = $_POST["CoreSite"];
$ActionAuditor = $_POST["ActionAuditor"];
$DCOSPOC = $_POST["DCOSPOC"];
if($stmt = $mysqli->prepare("Insert INTO DCO_Database (ActivityDate, CoreSite, ActionAuditor, DCOSPOC) Where (ActivityDate=? AND CoreSite=? AND ActionAuditor=? AND DCOSPOC=?)"))
{
$stmt->bind_param("ssss", $ActivityDate, $CoreSite, $ActionAuditor, $DCOSPOC);
$stmt->execute();
$stmt->close();
}
else{
echo ("Failed");
$mysqli->close();
}
?>
Run Code Online (Sandbox Code Playgroud)
我已编辑代码以使用值,而不是回显Failed但回显成功..但仍然没有向数据库添加值
<?php
$ActivityDate = $_POST["ActivitytDate"];
$CoreSite = $_POST["CoreSite"];
$ActionAuditor = $_POST["ActionAuditor"];
$DCOSPOC = $_POST["DCOSPOC"];
$AreaOwner = $_POST["AreaOwner"];
$ActionImplementer = $_POST["ActionImplementer"];
$ActionOwner = $_POST["ActionOwner"];
$MailSubject = $_POST["MailSubject"];
$ActionType = $_POST["ActionType"];
$RequestType = $_POST["RequestType"];
$RequestNumber …Run Code Online (Sandbox Code Playgroud)