I can not get to do this work, I have spent many hours on it now.
This works:
$ mysqli = new mysqli ("localhost", "root", "root", "db"); If (! $ Mysqli || $ mysqli- & gt; Connect_reno) {Return; } $ Query_str = "The name of the selection from the table WHERE city ('Nashville', 'Knoxville')"; If ($ query_prepared & amp; $ query_prepared- & gt; ready ($ query_str)) {$ query_prepared-> carry about (); But I can not find it to work with Bind_Param:
$ query_str = "Select the table from the name where in the city ( ?) "; $ Query_prepared = $ mysqli-> Stmt_init (); If ($ query_prepreted & amp; $ query_prepared- & gt; ready ($ query_str)) {$ cities = explosion (",", $ _GET ['cities']); $ Str_get_cities = "'" .implode ("', '", $ get_cities) "'"; // This equals 'Nashville', 'Knoxville' $ query- prepaid- & gt; Dam_param ("s", $ cities); $ Query_prepared- & gt; Executed (); call_user_func_array I have also tried, but it does not seem that any help would be appreciated to get the syntax correct. Edit: I tried hard to suggest Moskito-X and tons of examples listed here and otherwise where and on random websites, and nothing works. I think this problem may be PHP 5.4, which is now my MAMP
You can not force two variables with a question mark !
P> String value is later placed between quotes.
This will not work
"From the selection of the table in the city (?)"; (Gets) $ q_prepared-> Dam_param ("s", $ cities); "Select the table where from city to city ('city1, city2, city3, city4')"; Should be .
"Select the table from where in the city (?,?,?,?)"; (Too many) $ q_prepared- & gt; Dam_param ("ssss", $ city1, $ city2, $ city3, $ city4); "Select the table from which to select in the city ('city1', 'city2', 'city3', 'city4')"; $ query_prepared-> gt; Bind_param returns a string parameter one by one. The string and length of the string type must match the parameters in the statement statement. $ query_str = "Select the table WHERE Select from city ('Nashville', 'Knoxville')"; will be
$ query_str = "From the selection of the table in the city (?,?)"; should now be bind_param bind_param ("ss", $ arg1, $ arg2) with this
$ query_str = "Select the table from where in the city (?)"; and with bind_param bind_param ("s", $ cities) < P> you get $ query_str = "select the table from which city IN ('Nashville, Knoxville')"; That's why no array does not work.
The only solution for this fact is call_user_func_array if you are included in a statement, then it is unnecessary
$ query_prepared = $ Mysqli- & gt; Stmt_init (); If ($ query_prepared & amp; $ query_prepared- & gt; ready ($ query_str)) { this is correct
$ query_prepared = $ mysqli- & Gt; Stmt_init (); If ($ query_prepared-> Ready ($ query_str)) { If you do not want to use call_user_func_array
and you have only one Count small logic - you can do it with the following code. [...] $ cities = explosion (",", $ _GET ['city']); If (count ($ city)> 3) {"many arguments" echo; } And {$ count = count (cities $); $ SetIn = "("; for ($ i = 0; $ i <$ count; ++ $ i) {$ code. = 'S'; if ($ i> 0) {$ SetIn = ",?";} And {$ SetIn. = "?";}} $ SetIn. = ")"; $ Query_str = "Select the table from where in the city". $ SetIn; // will appear like $ query_str with two arguments // the selection name table WHERE city IN (?,?) $ Query_prepared = $ mysqli-> Stmt_init (); If ($ query_prepared- & gt; ready ($ query_str) {if ($ count == 1) {$ query_prepared-> bind_param ($ code, cities [0]);} if ($ count == 2) { $ Query_prepared- & gt; Bind_param ($ code, $ city [0], $ cities [1]);} if ($ count == 3) {$ query_prepared-> bind_param ($ code, $ cities [0], $ cities [1], $ Cities [2]); // $ query_prepared-> with 2 argument Bind_param) // $ query-prepared-> Bind_param ("ss", $ cities [0], $ cities [1]) $ $ query_prepared- & gt; Execute () will look like; } [...]} I think try to reach it to call_user_func_array . > Nick 9V
No comments:
Post a Comment