mysqli

select rows where same column values start with string, 2 questions

放肆的年华 提交于 2019-12-24 11:37:57
问题 I'm trying to get multiple sums of rows, each sum has a matching column string value, and all the values have a matching 4 character prefix, but it's not working and I could use some help. Also, would CASE be a more or less costly query on the db? Started with this: $sql = "SELECT col1 FROM table WHERE substr(col1,1,5)='$string'"; $query = mysqli_query($con, $sql); $row = mysqli_fetch_array($query,MYSQLI_ASSOC); $results = $row['col1']; $sum1 = count(array_keys($results,'string1')); $sum2 =

Return multiple row without the use of mysqlnd

こ雲淡風輕ζ 提交于 2019-12-24 11:35:42
问题 I dont have mysqlnd available, so i implemented a helper function to do the job: public function bind_array($stmt, &$row) { $md = $stmt->result_metadata(); var_dump($md); $params = array(); while($field = $md->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $params); } The trouble is, that i also need it to be able to return multiple rows. As of now it can only return a single row. Thanks.... EDIT: What im aiming for is getting the same

Persistent Login PHP and SQL

我的梦境 提交于 2019-12-24 11:35:32
问题 I'm a little unsure on how to connect all of my files together for this project. Basically I have a simple login screen which pulls the username and password from my registration table. Once they log in, I want them to be able to see a few random research papers that were assigned to them. I'll add the link in my database to the paper and then assign 2-3 papers for 2-3 users. However, currently when I log in, and click on the papers page, I'm getting the echo message that I'm not signed in.

$stmt->bind_param() dynamically if condition query

我是研究僧i 提交于 2019-12-24 11:30:11
问题 I have a php problem when want to bind_param dynamically when I using SELECT this is my php code $sql = 'SELECT ProductName, ProductId FROM Product WHERE 1=1' if($produkname != ''){ $sql .= ' AND ProdukName Like ?'; } if($produkcode != ''){ $sql .= ' AND Produkcode Like ?'; } if($stmt = $mysqli->prepare($sql)){ $stmt->bind_param ('ss', $produkname, $produkcode) $stmt->execute(); //else code } I cannot bind_param if one of $produkname or $produkcode value is empty 回答1: In your case, you can

Android http php json mysqli web services insert and retrieve data doesn't work

烈酒焚心 提交于 2019-12-24 11:25:31
问题 I don't know where the bug is. Hope someone can help me. Running it on real android device it returns "Incorrect user details" and howewer it doesn't send data to mysql server and then to database. If I run php files from chrome browser it works perfectly. I'm using wampp server as localhost. Thanks very much in advance. Android Manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wikibuyers.loginregister" > <uses

With mysqli and prepared statements can I PASS IN COLUMN NAMES to 'ORDER BY'

百般思念 提交于 2019-12-24 10:02:22
问题 I need to be able to use prepared MYSQLI statements for security reasons. I need to be able to ORDER BY COLUMNNAME DIRECTION However, the COLUMNNAME is DYNAMIC as is the DIRECTION (ASC/DESC) When I bind mysqli parameters I get 'COLUMNNAME' 'ASC' or 'COLUMNNAME' 'DESC' Whereas what I need is NO QUOTES........ Is there anyway to do this? I have seen someone ask something similar in Are PHP MySQLi prepared queries with bound parameters secure? 回答1: It is not possible to use parameter binding for

Warning: mysqli_close() expects parameter 1 to be mysqli

霸气de小男生 提交于 2019-12-24 09:57:44
问题 I have this PHP code on a WAMP server with MySQL and this error appears in a dialog box when I visit the site. How can I fix this? <?php // Create connection $con = mysqli_connect("localhost","userdb","userdb","apptestdb"); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // This SQL statement selects ALL from the table 'Locations' $sql = "SELECT * FROM Locations"; // Check if there are results if ($result = mysqli_query(

Throw an exception in a function or how to do descent error handling [closed]

↘锁芯ラ 提交于 2019-12-24 09:09:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am currently using MySQLi prepared statements for my database handling. Because MySQLi prepared statements only throw an error when the connection is wrong, I am forced to check for errors myself and to throw them myself too. In PDO (which I am going to use in the future because I'm convinced now it works way

How to display corresponding mysql columns in html based on option selected from dynamic dropdown list

巧了我就是萌 提交于 2019-12-24 09:00:31
问题 I would like to ask for help in displaying the corresponding mysql table columns after the user selects an option from the dynamic dropdown box. I really don't know where I went wrong :( please help :( I have 3 mysql tables: buildings, delivery_transaction and location, all connected to each other. The main table is the delivery transaction: [delivery_transaction table, where building_ID and location_ID are the FKs from the remaining 2 tables][1] Wherein if user will click on whatever

Prepared multiple Insert mysqli

泄露秘密 提交于 2019-12-24 08:57:54
问题 Please read the full question before closing it :) Im looking for a prepared statement with mysqli (Important, not PDO, because I can't use it and can't transfer some PDO code to mysqli.), where i can insert on long query with a lot of values (about 2000). But the query has to be prepared. So i started like that: $array = array("a1", "a2", "a3","a5", "a7", "a5","a9", "a32", "a3", "a4"); // AND SO ON UP TO 2000 $type = "s"; $end = count($array); $query = "INSERT INTO table (value) VALUES (?)";