Q&A

Q1:Is a program in C that interacts with MySQL always going to run faster than a program in another language?
A1: Not necessarily. It is true that in general a compiled language produces a program that executes faster than a script written in an interpreted language such as Perl or PHP. In this respect, a C program generally runs faster.

However, C lacks certain functionality that is present in Perl or PHP, such as text processing. If your C program has to implement in code that has core functionality in another language, any advantage will usually be lost, and the resulting program may be slower. Also, bear in mind that a significant amount of processing time may be spent running SQL queries. If these queries are complex, MySQL itself takes time to run them, no matter what language is chosen.

Q2:Do I really need to check whether a query runs successfully (it seems awfully complicated)?
A2: Checking for the successful completion of a database action is essential. If the program simply marches on after an error occurs, the results could be unpredictable, returning ugly results to the user and even corrupting data.

To put it simply, when you run mysql_query() or mysql_real_query(), they return a zero if the query executes successfully.

If you know your query was one that returns no result (such as an INSERT or UPDATE), you don't need to do further checking. However, you may want to call mysql_affected_rows() to find out how many rows were inserted, modified, or deleted.

If you know your query should return some data, you'll be doing a mysql_store_result(). This returns NULL if an error occurred; otherwise, a data structure of the type MYSQL_RES.

In today's lesson, we tested mysql_field_count() to determine whether an error occurred; however, this process is only necessary if you don't know what kind of query was being run (which is the case in a generic SQL handler like the mysql monitor).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.55.198