MySQL Questions and Answers – Handling Errors and Processing Command Options

This set of MySQL Database Multiple Choice Questions & Answers (MCQs) focuses on “Handling Errors and Processing Command Options”.

1. How many of the following use NULL to indicate failure?

mysql_init(), mysql_real_connect()

a) 0
b) 1
c) 2
d) 3
View Answer

Answer: c
Explanation: Both of the client library routines named ‘mysql_init()’ and ‘mysql_real_connect()’ return a pointer to the connection handler in order to indicate success and NULL to indicate failure.
advertisement
advertisement

2. How many of the following does not return a value?

	mysql_close(), mysql_init, mysql_real_connect

a) 0
b) 1
c) 2
d) 3
View Answer

Answer: b
Explanation: It is not necessary that every Application Programming Interface call would return a value. For example, the client routine named ‘mysql_close()’ returns void, that is, it does not return a value.

3. Which of these returns a string containing an error message?
a) mysql_error()
b) mysql_errno()
c) mysql_sqlstate()
d) mysql_close()
View Answer

Answer: a
Explanation: The API call named ‘mysql_error()’ returns a string containing an error message. ‘mysql_close()’ does not return any value at all. ‘mysql_errno()’ returns a MySQL-specific numeric code.
advertisement

4. Which of the following returns a MySQL-specific numeric code?
a) mysql_error()
b) mysql_errno()
c) mysql_sqlstate()
d) mysql_close()
View Answer

Answer: b
Explanation: The API call named ‘mysql_errorno()’ returns a MySQL-specific numeric error code. ‘mysql_error()’ returns a string containing an error message. ‘mysql_close()’ does not return any value at all.

5. Which of the following returns an SQLSTATE code?
a) mysql_error()
b) mysql_errno()
c) mysql_sqlstate()
d) mysql_close()
View Answer

Answer: c
Explanation: The MySQL API call named ‘mysql_sqlstate()’ returns an SQLSTATE code. This SQLSTATE value is more ‘vendor neutral’ because it is based on the ‘ANSI SQL’ and ‘ODBC’ standards.
advertisement

6. The argument to the function mysql_error() is _______________
a) integer
b) float
c) structure
d) pointer
View Answer

Answer: d
Explanation: The argument to the API functions ‘mysql_error()’, ‘mysql_errno()’ and ‘mysql_sqlstate()’ is a pointer to the connection handler. These should be called after an error occurs.

7. What does mysql_real_connect() return if it fails?
a) integer
b) float
c) structure
d) NULL
View Answer

Answer: d
Explanation: The function ‘mysql_real_connect()’ must complete successfully before any other API functions that require a valid MYSQL connection handler structure can be executed. It returns NULL on failure.

8. The function load_defaults() reads the option files.
a) True
b) False
View Answer

Answer: a
Explanation: The function named ‘load_defaults()’ reads the option files. It takes four arguments. It does not pick up values from the environment settings. All connection parameters can be brought to the argument vector.

9. The –protocol value ‘TCP’ runs on which operating systems?
a) unix only
b) windows only
c) all
d) none
View Answer

Answer: c
Explanation: The connection protocol used by the option ‘–protocol = TCP’ indicates TCP/IP connection to the local or the remote server. Each –protocol value has the set of the permissible OS.

10. All API calls return a value.
a) True
b) False
View Answer

Answer: b
Explanation: In MySQL, not all the API calls return a value. The client routine named ‘mysql_close()’ is one that does not. The API calls that return a value are ‘mysql_sqlstate()’, ‘mysql_error()’ etc.

Sanfoundry Global Education & Learning Series – MySQL Database.

To practice all areas of MySQL Database, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.