$ stmt究竟是什么?它的目的是什么?它代表什么..
我正在关注使用预准备语句的教程,并在手册中查找stmt:http: //php.net/manual/en/class.mysqli-stmt.php
并且看到它是一个"代表一个准备好的语句"的类 - 我猜这是一个准备好的sql语句,你将一个变量插入.虽然我没有看到这个id如何将sql语句存储为字符串然后在需要时操纵字符串以添加变量?
private void Update_Record_Click(object sender, EventArgs e)
{
ConnectionClass.OpenConnection();
if (textBox4.Text == "" && textBox2.Text == "")
{
MessageBox.Show("No value entred for update.");
}
else if (textBox4.Text != "" && textBox2.Text != "")
{
SqlCommand cmd = new SqlCommand("update medicinerecord set quantity='" + textBox2.Text + "' where productid='"+comboBox1.Text+"'", ConnectionClass.OpenConnection());
cmd.ExecuteNonQuery();
cmd = new SqlCommand("update myrecord set price='" + textBox4.Text + "' where productid='" + comboBox1.Text + "'", ConnectionClass.OpenConnection());
cmd.ExecuteNonQuery();
ConnectionClass.CloseConnection();
}
else if (textBox2.Text != "")
{
SqlCommand cmd = new …Run Code Online (Sandbox Code Playgroud) 我在MySQL中遇到错误:
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '''')' at line 2'.
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<form action="read_message.php" method="post">
<table class="form_table">
<tr>
<td style="font-weight:bold;">Subject:</td>
<td><input style=" width:300px" name="form_subject"/></td>
<td></td>
</tr>
<tr>
<td style="font-weight:bold;">Message:</td>
<td id="myWordCount"> (300 words left)</td>
<td></td>
</tr>
<tr>
<td><input type="hidden" name="sender_id" value="<?php echo $sender_id?>"></td>
<td><textarea cols="50" rows="4" name="form_message"></textarea></td>
<td valign="bottom"><input type="submit" name="submit_message" value="send"></td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
要插入mysql表的代码:
<?php
include_once"connect_to_mysql.php";
//submit new message
if($_POST['submit_message']){ …Run Code Online (Sandbox Code Playgroud) 我知道这里有关于同样问题的SO有多个问题,我已经调查了它们但是并没有得到令人满意的答案.所以这是我的问题,
我有一个由几个文本框和复选框组成的表单.看起来像这样,

用户可以选择多个复选框.我正在尝试将这些复选框的值(而不是显示文本字符串)插入到MySQL表中.看起来应该是这样的,

一个服务ID(SID)可以有多个位置(Loc_Code).这些位置代码(CO,GQ)是复选框的值.
到目前为止,我已经编写了以下代码.
<html>
<head>
</head>
<body>
<?php
require_once("db_handler.php");
$conn = iniCon();
$db = selectDB($conn);
/* Generating the new ServiceID */
$query = "SELECT SID FROM taxi_services ORDER BY SID DESC LIMIT 1";
$result = mysql_query($query, $conn);
$row = mysql_fetch_array($result);
$last_id = $row["SID"];
$id_letter = substr($last_id, 0, 1);
$id_num = substr($last_id, 1) + 1;
$id_num = str_pad($id_num, 3, "0", STR_PAD_LEFT);
$new_id = $id_letter . $id_num;
//Selecting locations
$query = "SELECT Loc_Code, Name FROM districts";
$result = …Run Code Online (Sandbox Code Playgroud) 我正在尝试插入格式化为2012年8月12日的日期,但是当我在插入后检查数据库集时,我只能在日期字段中看到00-00-0000?
这是我使用的查询:
$query= "INSERT INTO ambition_opportunities SET
opp_deadline='".strtotime($_POST['deadline'])."'"; // date field come with date picker**
$sql = mysql_query($query) or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试创建一个需要4个参数的存储过程.这4个参数决定了返回表的外观.
@C_ID参数始终为数字.@U_ID和@P_ID值可以包含有效的数值,或者可以(或应该)传递,NULL因为WHERE条件执行或不执行.
ALTER PROCEDURE [dbo].[GetData]
@C_ID integer,
@U_ID integer = Null,
@P_ID integer = Null,
@SortIndex integer = 1
AS
BEGIN
SELECT
ID, P_ID, U_Name, P_Name,
FORMAT(Date_When, 'dd/MM/yyyy hh:mm tt')
FROM
SomeTable
WHERE
C_ID = @C_ID
AND (@P_ID IS NULL OR P_ID = @P_ID)
AND (@U_ID IS NULL OR U_ID = @U_ID)
ORDER BY
CASE WHEN @SortIndex = 1 THEN -ID
ELSE ID
END ASC
END
Run Code Online (Sandbox Code Playgroud)
在SQL Server 2014上,以下执行工作正常,没有任何错误:
exec GetData …Run Code Online (Sandbox Code Playgroud) 我试图找到如何将查询中的变量发送到触发器,但它会影响第二个表.我正在使用它来创建一个日志表,其中任何更新或插入的内容都会记录在日志表中.例如
//Inserts into the table the username and password
$sql = "INSERT INTO table VALUES ($_POST['username'], $_SESSION['password']);
Run Code Online (Sandbox Code Playgroud)
触发DDL语句
DELIMITER $$
//Creates trigger to insert into table1 ( logs ) the userid and patientid ( which has to come from php )
USE `baemer_emr`$$
CREATE
DEFINER=`baemer_emr`@`localhost`
TRIGGER `table1`.`after_insert`
AFTER INSERT ON `baemer_emr`.`table1`
FOR EACH ROW
BEGIN
INSERT INTO table2 VALUES (NEW.idn, $_POST[userid], $_SESSION[patientid]);
END$$
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我无法使用MySQL和Drupal 7获得不区分大小写的查询.这是我的模块代码:
$results = db_select('people_table', 'p')->fields('p');
if (array_key_exists('department', $_GET)) {
$results->condition('Department', '%' . db_like($_GET['department']) . '%', 'LIKE');
}
return $results->orderBy('Name', 'ASC')->execute();
Run Code Online (Sandbox Code Playgroud)
随着?department=Chemistry在URL中,我得到三个结果.随着?department=chemistry在URL中,我没有得到任何结果.当我尝试时$results->condition('UPPER(Department)'...,我收到此错误:
PDOException:SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'UPPERDepartment':SELECT p.*FROM {people_table} p WHERE(UPPERDepartment LIKE:db_condition_placeholder_0 ESCAPE'\\')ORDER BY Name ASC;
所以看起来它吃掉了我的括号.我怎么能不区分大小写LIKE?
编辑:Department列和整个表上 的排序规则是utf8_bin. 这个答案说:"唯一特别的是utf8_bin,用于比较二进制格式的字符." 我不知道为什么选择这种排序规则,因为表中的所有数据都是英文文本.我可能只是将整理更改为utf8_general_ci.
当我想基于删除整行时,我遇到了问题id_curse.这是我的代码,这是我得到的错误:
Oracle.DataAccess.dll中发生了未处理的"Oracle.DataAccess.Client.OracleException"类型异常.
附加信息:
外部组件引发的异常.
你能帮我解决这个问题吗?我认为SQL命令中的代码对此不利.
private void button3_Click(object sender, EventArgs e)
{
Oracle.DataAccess.Client.OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection(provider);
Oracle.DataAccess.Client.OracleCommand cmd = new Oracle.DataAccess.Client.OracleCommand();
conn.Open();
cmd = new Oracle.DataAccess.Client.OracleCommand(" DELETE * from CURSE WHERE ID_CURSA = '" + textBox1.Text + "'", conn);
cmd.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud) 我对专业编程相对缺乏经验,但我正在尝试编写一个与MS Access数据库接口的程序.基本上我正在收集表单中的信息,并尝试在每个条目的新行传递信息.我有一个开放的OleDbConnection,我的测试显示我能够看到哪个行将有新条目,但是当我点击提交按钮时,catch中没有显示错误,但数据库保持不变.我最初在我从click事件调用的方法中获得了代码,但我只是将代码放到事件处理程序中以验证问题不在于调用.
private void btnSubmit_Click(object sender, EventArgs e)
{
if (DBConnection.State.Equals(ConnectionState.Closed))
{
DBConnection.Open();
}
try
{
MessageBox.Show("Save Data at index: " + intRowPosition.ToString());
OleDbCommand OledbInsert = new OleDbCommand("Insert INTO RetentionTable (DateTime,Center,CSP,MemberID,ContractNumber,RetentionType,RetentionTrigger,MemberReason,ActionTaken,Other) VALUES('" + DateTime.Now.ToString() + "','" + GetCenter("") + "','" + GetName("") + "','" + GetMemberID("") + "','" + GetContractNumber("") + "','" + GetType("") + "','" + GetTrigger("") + "','" + GetReason("") + "','" + GetAction("") + "', + GetOther("")," DBConnection);
intRowPosition++;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
MessageBox.Show(ex.StackTrace.ToString());
} …Run Code Online (Sandbox Code Playgroud)