Ask why the returned value cannot be obtained in the second method-php Tutorial

Source: Internet
Author: User
Why can't I get the return value in the following ways? This post is finally edited by u010416883 from 2013-06-011:37:22! Public & nbsp; static & nbsp; function & nbsp; query ($ SQL, & nbsp; $ unbuffered & nbsp; false) & nbsp ;{& nbsp; why can't I get the return value in the following ways?

This post was last edited by u010416883 at 11:37:22

Answer the following questions!

Public static function query ($ SQL, $ unbuffered = false ){
$ Ret = self ::$ db-> query ($ SQL, $ unbuffered); // when the sentence is successful, $ ret is 1 Note: self :: $ db-> query is mysql_query
If ($ unbuffered === true ){
$ Cmd = trim (strtoupper (substr ($ SQL, 0, strpos ($ SQL ,''))));
If ($ cmd = 'select '){}
Elseif ($ cmd = 'update' | $ cmd = 'delete '){
$ Ret = self: $ db-> affected_rows ();
}
Elseif ($ cmd = 'insert '){
$ Ret = self: $ db-> insert_id (); // it indicates that the task is executed and the int type ID is returned.
}
}
Return $ ret; // The final return is not an int-type idnumber.
}

Share to:... 'data-pics = ''>


------ Solution --------------------
What do you get?
------ Solution --------------------
No matter whether there are any subsequent operations, at least $ ret = self: $ db-> query ($ SQL, $ unbuffered); is returned.
If yes, $ ret is 1 when the sentence is successful, and you say the return is null, it is obviously a query failure.
------ Solution --------------------
Public function query ($ SQL, $ unbuffered = false) {...
Either query returns resources or query returns logical values.
------ Solution --------------------
What is the SQL statement you run? What is $ unbuffered during query execution?
------ Solution --------------------
You use elseif. if a condition breaks the following program, it will not go any more.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.