首页 \ 问答 \ PHP bind_param与数组(PHP bind_param with arrays)

PHP bind_param与数组(PHP bind_param with arrays)

是否可以将bind_param()与数组一起使用?

例如

$stmt->bind_param('iss', Array(101, 'SomeString 1', 'Some string 2'));
// OR
$stmt->bind_param(Array('iss'), Array(101, 'String1', 'String2'));
// OR
$stmt->bind_param(Array( Array('i', 101), Array('s', 'String1'), Array('s', 'String2') ));

这些示例中的任何一个都可以在PHP(或任何其他示例)中使用吗?

最后我可以使用我的函数/类

$sql->upload( $table, Array('n;id', 's;username=' . $username, 's;password=' . $password) );

功能探索

public function upload( String $table , Array $values )

// Where example array could be Array('s;column=someString', 'i;SomeIntegerColumn=10', 'n;SomeID')
/*
    identifier;column=value
    Basically where identifier can be "n", "d", "i" or "s"
    column is the name of the sql column to inset the value to
    value is the string/integer/double to instert in the the column

    Example query with the array mentioned above would be
    "INSERT INTO $table(column, SomeIntegerColumn, SomeID) VALUES(?, ?, NULL)"
*/

我的项目很快就会出现在GitHub上:)非常感谢!


Is it possible to use bind_param() with arrays?

For example

$stmt->bind_param('iss', Array(101, 'SomeString 1', 'Some string 2'));
// OR
$stmt->bind_param(Array('iss'), Array(101, 'String1', 'String2'));
// OR
$stmt->bind_param(Array( Array('i', 101), Array('s', 'String1'), Array('s', 'String2') ));

Is any of these examples possible in PHP (or any other examples)?

Finally I can use my function/class

$sql->upload( $table, Array('n;id', 's;username=' . $username, 's;password=' . $password) );

Function explination

public function upload( String $table , Array $values )

// Where example array could be Array('s;column=someString', 'i;SomeIntegerColumn=10', 'n;SomeID')
/*
    identifier;column=value
    Basically where identifier can be "n", "d", "i" or "s"
    column is the name of the sql column to inset the value to
    value is the string/integer/double to instert in the the column

    Example query with the array mentioned above would be
    "INSERT INTO $table(column, SomeIntegerColumn, SomeID) VALUES(?, ?, NULL)"
*/

My project will be out on GitHub really soon :) Thanks a lot!


原文:https://stackoverflow.com/questions/40717625
更新时间:2019-12-03 08:12

最满意答案

如果您的PHP没有过时(即=> 5.6),只需在第一个示例中添加三个点,

$stmt->bind_param('iss', ...array(101, 'SomeString 1', 'Some string 2'));

If your PHP is not outdated (>= 5.6 namely), just add three dots to the first example,

$stmt->bind_param('iss', ...array(101, 'SomeString 1', 'Some string 2'));
2016-11-21

相关问答

更多

silverlight在绑定中的表达(silverlight expression in binding)

您不能绑定到Binding中的多个源属性。 因此,您需要某种聚合器,它提供可以绑定的输出属性。 以下是相同模式的一些变体: <UserControl.Resources> <sys:Double x:Key="width">10</sys:Double> <sys:Double x:Key="margin">30</sys:Double> <BindableResult x:Key="widthPlusMargin" ArithmeticOperation="Add" L

设置减速器的数量不起作用(set the number of reducers does not work)

-D mapred.reduce.tasks=2 \ -fs local \ -jt local 通过检查-fs和-jt值,我知道你是在local模式下运行它。 在local模式下, 零或一个减速器最多可以运行 。 因为它使用本地文件系统和单个JVM,所以在此模式下没有Hadoop守护程序。 在psuedo distributed模式下,所有守护进程在同一台机器上运行,属性-D mapred.reduce.tasks=n将起作用并产生n reducers。 所以你应该使用psuedo dist

两个日期之间每天的算术平均值(arithmetic mean per day between two dates)

如果你不能改变其他答案中提到的查询,这里是获得所需结果的php代码。 使用键作为日期创建一个新数组。 计算每个日期的平均值。 PHP代码 foreach($values as $val){ // generates array with date as key $dates[$val['date']][] = $val['lig']; } foreach($dates as $k=>$v){ // calculates mean value for each date

ListView没有正确绑定使用(ListView not binding properly using)

您需要创建一个属性并绑定到该属性。 例如在你的viewmodel中: public ObservableCollection<FieldSample> FieldAnalysis { get { return fieldAnalysis; } } 那么在你看来: ItemsSource="{Binding FieldAnalysis}" You need to create a property and bind to the property. E.g. in yo

Booststrap数据表无法在Web托管上工作(Booststrap datatable not working on web hosting)

它现在正在运作。 我刚试过包含jquery和datatables CDN。 问题是我没有引用jquery,并且数据库库的路径是错误的。 使用下面的脚本添加jquery和datatables <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.

与lodash的组数组(Group array with lodash)

使用_.groupBy() ,然后将_.map()分组对象添加到请求的表单: var arrList = [{"email":"a@mailinator.com","pname":"john doe1"},{"email":"a@mailinator.com","pname":"john doe2"},{"email":"a@mailinator.com","pname":"john doe3"}]; var result = _(arrList) .groupBy('email')

创建数据库,如果不存在php mysql(create database if not exists php mysql)

您尝试使用的用户没有使用CREATE权限 尝试切换到另一个用户,该用户拥有操纵数据库所需的所有权限,或者向您正在使用的用户添加所需的权限 the users you are trying to use have no priviledges to use CREATE try to switch to another user that have all the priviledges needed on manipulting the database or add the needed pr

Javascript定时循环与PHP(Javascript timed loop with php)

JavaScript可以根据您当地时间调用时间戳。 使用setInterval循环并更新Date.now()给出的时间戳。 setInterval(function() { document.getElementById("timestamp").innerHTML = Date.now(); }, 16); 见jsFiddle 。 JavaScript can call up a timestamp based on your local time. Use setInterval

相关文章

更多

最新问答

更多
  • 读取UITextfields的值时出错(Error in reading values of UITextfields)
  • 将javascript变量分配给java变量(Assigning javascript variable to java variable)
  • ActiveRecord_Associations_CollectionProxy的未定义方法(Undefined method for ActiveRecord_Associations_CollectionProxy)
  • 返回两个字符串作为方法签名(Return two strings as method signature)
  • 在弹簧启动应用程序中自动连接对象(Auto wiring an object in spring boot application)
  • Log4j2 - 当前日期文件追加不起作用(Log4j2 - current date file append not working)
  • 如果已经使用计时器运行,如何解决不受欢迎的webrequest调用?(How to solve undesirable webrequest call if it is already running with timer?)
  • 释放全局变量(Freeing global variable)
  • 如何在标头中添加单独的列以便在jqgrid中进行垂直滚动(How to add separate column in header for vertical scrolling in jqgrid)
  • Javascript / jQuery切换边栏[关闭](Javascript/jQuery Toggling Sidebar [closed])
  • 套接字客户端:没有得到DataInputStream.readUTF()的完整响应(Socket client: don't get the full response with DataInputStream.readUTF())
  • 一个月的数字表示,带或不带前导零(Numeric representation of a month, with or without leading zeros)
  • SAS proc freq用于变量的不同值(SAS proc freq for distinct value of a variable)
  • 将pkg.sub导入为other.sub(importing pkg.sub as other.sub)
  • PaperJs错误并不明显(PaperJs errors are not understable)
  • 访问正文中脚本之外的javascript var(accessing a javascript var outside of script in the body)
  • 使用PowerShell查询单个注册表子项?(Query a single registry subkey using PowerShell?)
  • 可以省去do-while循环中的“do”吗?(Can leaving out the “do” in a do-while loop still work?)
  • Firestore规则:数据为数字时条件检查失败(Firestore rules: condition check fails when data is number)
  • Python:为什么在迭代时会忽略序列的__len __()?(Python: Why is the __len__() of a sequence ignored when iterating?)
  • PlayN中没有发现OpenGL上下文错误(No OpenGL context found error in PlayN)
  • 如何在AWS CodeCommit存储库中创建文件夹?(How to create folder in AWS CodeCommit repository?)
  • awk:将结果发送到使用bash变量命名的文件(awk: send results to file named using bash variable)
  • 卸载视图时防止丢失状态(Prevent loss of state when unmounting view)
  • Android EditText字段在模拟器上运行正常,但不适用于设备(Android EditText field works fine on emulator, but not device)
  • AngularJS在条件有效的ng-repeat中禁用未选中的复选框(AngularJS Disable unchecked checkbox in ng-repeat with condition)
  • codeigniter加载一个没有任何html标题的视图进行打印(codeigniter load a view without any html header for printing)
  • Liferay porlet的动作网址中的例外情况(Exception in the action url of liferay porlet)
  • 条目(XAML表单)对象引用仅与UWP App一起使用(Entry (XAML Form) object reference null only with UWP App)
  • Spring项目中的额外Gradle任务(Extra Gradle tasks in Spring project)