Snart Posted January 31, 2009 Share Posted January 31, 2009 Hi When I try to use mysqli_num_rows on a "CREATE TABLE" statement, it returns me the error "mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in ...". This is because the CREATE statement doesn't return a number of rows like a SELECT statement would. Is there a clean way to deal with this error? Either by somehow finding out which "type" of query I'm dealing with (a substring extracting the first word of the query could do the trick, but it doesn't feel right) or by error-free testing if mysqli_num_rows is applicable (adding a @ before the function would also do the trick but is, again, not a really clean way). BTW, I'm using a home-brewn general-purpose query function which launches queries for me and which automatically retrieves results. So it's not a matter of calling mysqli_num_rows only when I launch a SELECT statement, my function doesn't know which type of query is used and I'm not too fond of having to pass the type each time as an argument. Cheers Snart Quote Link to comment https://forums.phpfreaks.com/topic/143284-solved-mysqli_num_rows-on-queries-which-dont-return-a-number/ Share on other sites More sharing options...
FezEvils Posted January 31, 2009 Share Posted January 31, 2009 i'm suggesting you for using xampp. it more easy to create db and generate result very quickly Quote Link to comment https://forums.phpfreaks.com/topic/143284-solved-mysqli_num_rows-on-queries-which-dont-return-a-number/#findComment-751484 Share on other sites More sharing options...
Snart Posted January 31, 2009 Author Share Posted January 31, 2009 I used xampp in the past, currently I use wampserver. But the issue is not the creation of the tables (which has to be done via script, not phpmyadmin and such) but the fact that a "CREATE TABLE" statement generates an error when I use mysqli_num_rows(). I need a way to either test if mysqli_num_rows will work properly on the query, or determine if the query that is being launched is a CREATE statement or SELECT statement or something else. Quote Link to comment https://forums.phpfreaks.com/topic/143284-solved-mysqli_num_rows-on-queries-which-dont-return-a-number/#findComment-751502 Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 http://php.net/stripos You could just see if the string starts with UPDATE or SELECT. Quote Link to comment https://forums.phpfreaks.com/topic/143284-solved-mysqli_num_rows-on-queries-which-dont-return-a-number/#findComment-751809 Share on other sites More sharing options...
Snart Posted February 1, 2009 Author Share Posted February 1, 2009 Yeah, I'm beginning to think this is the only way to do this. Are there any possible queries you can think of that don't start with the relevant keyword (select, insert, show, delete, ...)? Quote Link to comment https://forums.phpfreaks.com/topic/143284-solved-mysqli_num_rows-on-queries-which-dont-return-a-number/#findComment-751866 Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 Hrmmmm.... No I think they all start with stuff like that. Quote Link to comment https://forums.phpfreaks.com/topic/143284-solved-mysqli_num_rows-on-queries-which-dont-return-a-number/#findComment-751997 Share on other sites More sharing options...
Snart Posted February 1, 2009 Author Share Posted February 1, 2009 Okido, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/143284-solved-mysqli_num_rows-on-queries-which-dont-return-a-number/#findComment-752043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.