mysqli

Generate nested JSON from SQL using PHP

纵饮孤独 提交于 2020-01-17 04:48:27
问题 I'm trying to generate a JSON API using PHP to be used as remote server interface for my Android application database. I managed to generate JSON like this: { products: [ { product_name: "Samsung", product_category: "phones", shop_name: "Gadget Store", user_id: "1", price: "1999", date: "2015-04-05", time: "11:14:44" }, { product_name: "Samsung", product_category: "phones", shop_name: "IT Store", user_id: "1", price: "1899", date: "2015-04-01", time: "13:00:00" }, { product_name: "Motorola",

Optimize PHP Mysqli Query Correctly

那年仲夏 提交于 2020-01-17 04:36:06
问题 I have recently had some help with INNER JOIN coding to help optimize a slow script that I have. After optimizing the remaining code and testing it I have now been able to identify that it is the queries below that are severley slowing the script down. Can anyone help me optimize the code below to make the queries faster. The indexes are fine, I think the code is just out of date now. $cqry = "SELECT * FROM ftree_node WHERE id IN "; if($wrow['A'] == 'F') { $cqry .= '(SELECT DISTINCT t1

re SQL Injection Attack using MySQL, what are baseline requirements?

半世苍凉 提交于 2020-01-17 03:54:07
问题 In current project using MySQL. Looking into the mysqli functions, found them to be very difficult to use. In my opinion, any programmer using the library should have a Medal of Honor. Three problems: mysqli does not handle NULL or functions such as CURRENT_DATE it is impossible to use paramterized SQL statements for queries with random WHERE clauses (so how do you prevent SQL Injection attacks?) in my opinion, it's too much work to use sqli in complicated cases (see link) PDO does not solve

What does Apache need to support both mysqli and PDO?

孤街浪徒 提交于 2020-01-17 03:42:09
问题 I'm considering changing some PHP code to use PDO for database access instead of mysqli (because the PDO syntax makes more sense to me and is database-agnostic). To do that, I'd need both methods to work while I'm making the changeover. My problem is this: so far, either one or the other method will crash Apache . Right now I'm using XAMPP in Windows XP, and PHP Version 5.2.8. Mysqli works fine, and so does this: $dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);

Finding many matches to one row in the same table and getting results from a second table based on the results

杀马特。学长 韩版系。学妹 提交于 2020-01-16 19:43:14
问题 I know that the question title may not be quit clear to understand but I try to explain: users_table: id | name | admin | property_id ----------------------------------- 1 | x | 1 | 0 2 | y | 1 | 0 3 | z | 0 | 1 5 | t | 0 | 2 6 | u | 0 | 2 7 | o | 0 | 2 users_table has two or more records which are admin and some other records which belong to one of these admin records by matching the property_id with the id . In the end what I want is the admin row data and the count of its properties . This

Finding many matches to one row in the same table and getting results from a second table based on the results

喜夏-厌秋 提交于 2020-01-16 19:43:05
问题 I know that the question title may not be quit clear to understand but I try to explain: users_table: id | name | admin | property_id ----------------------------------- 1 | x | 1 | 0 2 | y | 1 | 0 3 | z | 0 | 1 5 | t | 0 | 2 6 | u | 0 | 2 7 | o | 0 | 2 users_table has two or more records which are admin and some other records which belong to one of these admin records by matching the property_id with the id . In the end what I want is the admin row data and the count of its properties . This

Stored Procedures and Prepared Statements ins PHP mysqli

做~自己de王妃 提交于 2020-01-16 19:41:11
问题 Could you please help me with this: I'm coding PHP and have created a stored procedure in MySQL that receives two input values and return one output parameter DELIMITER $$ USE `ejemplo`$$ DROP PROCEDURE IF EXISTS `insert_sp`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_sp`( IN ID VARCHAR(8), IN Nombre VARCHAR(50), OUT msg VARCHAR(50) ) BEGIN INSERT INTO empleado_php VALUES (ID, Nombre); SELECT "Todo bien" INTO msg; END$$ DELIMITER ; and call this via mysqli, everythings works just

Nested looping with mysqli and fetch_object

房东的猫 提交于 2020-01-16 15:44:50
问题 I'm attempting to do a comparision between two tables. If I find a match, I need to copy data from one table and insert it into the other. I'm able to pull the data from the tables just fine, but I'm having issues with a nested loop I created. It only loops through and finds one result. When looking through the tables, there are 1000s of matches, so I assume I'm doing something wrong. My only guess is the use of fetch_object and how I'm using it. I attempted using fetch_assoc instead, but I

Nested looping with mysqli and fetch_object

二次信任 提交于 2020-01-16 15:44:14
问题 I'm attempting to do a comparision between two tables. If I find a match, I need to copy data from one table and insert it into the other. I'm able to pull the data from the tables just fine, but I'm having issues with a nested loop I created. It only loops through and finds one result. When looking through the tables, there are 1000s of matches, so I assume I'm doing something wrong. My only guess is the use of fetch_object and how I'm using it. I attempted using fetch_assoc instead, but I

Nested looping with mysqli and fetch_object

帅比萌擦擦* 提交于 2020-01-16 15:43:09
问题 I'm attempting to do a comparision between two tables. If I find a match, I need to copy data from one table and insert it into the other. I'm able to pull the data from the tables just fine, but I'm having issues with a nested loop I created. It only loops through and finds one result. When looking through the tables, there are 1000s of matches, so I assume I'm doing something wrong. My only guess is the use of fetch_object and how I'm using it. I attempted using fetch_assoc instead, but I