when using business to deal with PHP problems, it is certain to take into account the interaction (mysql, redis, memcached.) between programs. The return value of.
generally speaking, for the business, we will consider what to do if the database insertion fails, what to do if the redis command fails to execute, which may be caused by the network timeout or the server crash, but when these situations occur, I often don"t know what to do on the program side, for example, database insertion failure, So does the inset method of pdo return a false or does the program report an exception directly? The network is disconnected when phpredis is operating redis. Does it return null or program exception? In the final analysis, it is unfamiliar with the return value of each method or the way the class library handles various reasons that may not succeed, which leads to the need to use a strict judgment such as if $return= 1 to determine the next program direction, resulting in untidy code.
has considered using try and catch to wrap the entire database insertion code segment, but is afraid that the failure to insert will return only $return=0,. That loses its meaning.
I would like to ask you, when dealing with the logic of interacting with mysql and redis, is there a unified memory method to judge whether the command execution is successful or failed? Or must remember through documentation that each method is executed for every error (network disconnection, server to be interacted with crashes, connection denied.) Can you only keep the return value in mind?