sql server - How to debug "Object of class mysqli could not be converted to string" error in PHP? -


i working on academic project, , stuck in search feature, query trying run running smoothly in mysql server, when try run on application, giving me error this:

catchable fatal error: object of class mysqli not converted string in..........

the code snippets follows:

database connection:

<?php error_reporting(e_all); define("dbname","foodfood"); global $con; $servername = "localhost"; $username = "root"; $password = "passport";  // create connection $con = mysqli_connect($servername, $username, $password);  // check connection if (!$con) {     die("connection failed: " . mysqli_connect_error()); } ?> 

the query causing error:

function find_food ($keysearch, $con) {         $find_query = "select `vendor`.`v_id`,`vendor`.`v_name`,`vendor`.`v_img`,`contacts`.`cont_addr`,`contacts`.`cont_phn`,`fooditem`.`item_name`,`fooditem`.`fi_price`,`fooditem`.`fc_desc` vendor left join ".dbname.".`contacts` on `vendor`.`cont_id` = `contacts`.`cont_id`  left join ".dbname.".`fooditem` on `vendor`.`v_id` = `fooditem`.`v_id`  `vendor`.`v_name` '%".$keysearch."%' or `fooditem`.`item_name` '%".$keysearch."%';";  //run query $fill_food = mysqli_query($con, $find_query); } 

now, when run code, inputting search variable $keysearch (the variables filtered possible injection attacks). error on line is:

left join ".dbname.".`fooditem` on `vendor`.`v_id` = `fooditem`.`v_id`  `vendor`.`v_name` '%".$keysearch."%' or `fooditem`.`item_name` '%".$keysearch."%';"; 

update: debugged code , came more information. did var_dump of variables search page $keyword being picked up. seems fine , entered search string in var_dump. gets interesting when keyword gets parsed in next file have entered sql statement. have output of var_dump of same keyword , can see mysqli object follows:

object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $id: f373ea5dd5538761406a8022a4b8a374418b240e $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> null ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via tcp/ip" ["info"]=> null ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.6.21" ["server_version"]=> int(50621) ["stat"]=> string(130) "uptime: 550 threads: 1 questions: 5 slow queries: 0 opens: 70 flush tables: 1 open tables: 63 queries per second avg: 0.009" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(4) ["warning_count"]=> int(0) }  

now when put sql query in search page itself, dont error specified. sql query ready execute follows:

string(413) "select `vendor`.`v_id`,`vendor`.`v_name`,`vendor`.`v_img`,`contacts`.`cont_addr`,`contacts`.`cont_phn`,`fooditem`.`item_name`,`fooditem`.`fi_price`,`fooditem`.`fc_desc` vendor left join stfood.`contacts` on `vendor`.`cont_id` = `contacts`.`cont_id` left join stfood.`fooditem` on `vendor`.`v_id` = `fooditem`.`v_id` stfood.`vendor`.`v_name` '%vend%' or stfood`fooditem`.`item_name` '%vend%';"  

now, if take query , stick in mysql server query, query fails, , if remove double quotes ("") , run query, runs. have similar statements in other functions , run properly, not one. can guide me on making mistake?? in advance.

finally, did it... sql queries lots of foreign keys causing issues, made changes in script. * put search terms , sql queries on same page. * small changes in sql queries. * used mysqli_num_rows on mysqli_result object, stored results in variables , echoed on tables. phew........


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -