php - unable to select id mysqli -


i have query selects random rows table , trying select id along 3 rows when include id selected gives me error. if remove id query works fine. reason need id because need pass via url second page. missing?

call member function execute() on non-object  

the query:

   $stmt = $mydb->prepare("select  id, title, price, image_one         products r1 join            (select (rand() *              (select max(id)          products )) id)         r2  r1.id >= r2.id , title != ''  order r1.id asc  limit 1 ");  $stmt->execute(); 

you're missing error checking.

every time prepare or execute query, should check result. function returns false if there's error.

for example, if try running query, error:

error 1052 (23000): column 'id' in field list ambiguous 

there 2 id columns in query: r1.id , r2.id. need qualify column it's unambiguous 1 mean query.

select r1.id, title, ... 

but more important, check result returned prepare().

$stmt = $mydb->prepare(...); if ($stmt === false) {     trigger_error($mydb->error, e_user_error); } 

the same thing applies execute(), because can cause execution-time errors:

if ($stmt->execute() === false) {     trigger_error($stmt->error, e_user_error); } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -