Home arrow PHP arrow Page 10 - PHP 101 (part 4) - Look, Ma...It's Alive!

Oops! - PHP

One of the most compelling things PHP has going for it is it support for a wide variety of databases. And this week, PHP 101 is going to take advantage of that database support to create dynamic data-driven Web sites. This primer covers different techniques to select, insert and delete records, together with some tips to track and squash bugs when building SQL-driven sites.

TABLE OF CONTENTS:
  1. PHP 101 (part 4) - Look, Ma...It's Alive!
  2. Dumped!
  3. Hello Database!
  4. Different Strokes...
  5. ...For Different Folks
  6. What's In A Name?
  7. New Friends
  8. Today's Special
  9. Nuking The People
  10. Oops!
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 4
September 01, 2000

print this article
SEARCH DEV SHED

 
TOOLS YOU CAN USE

advertisement
All done? Nope, not quite yet - before you go out there and start building cool data-driven Web sites for your customers, you should be aware that PHP comes with some powerful error-tracking functions which can speed up development time. Take a look at the following example, which contains a deliberate error in the SELECT query string:


<?php // connect $connection = mysql_connect("localhost", "test", "test") or die("Invalid server or user"); mysql_select_db("php101",$connection) or die("Invalid database"); // query $query = "select from url_list"; // result $result = mysql_query($query,$connection); if(!$result) { $error_number = mysql_errno(); $error_msg = mysql_error(); echo "MySQL error $error_number: $error_msg"; } ?>
And here's the output:

MySQL error 1064: You have an error in your SQL syntax near 'from url_list' at line 1
The mysql_errno() function displays the error code returned by mySQL if there's an error in your SQL statement, while the mysql_error() function returns the actual error message. Turn these both on, and you'll find that they can significantly reduce the time you spend fixing bugs.

And that's about all we have for this issue of PHP 101. Next week, we'll be wrapping things up with a look at PHP's file read/write capabilities, and we'll also show you how to define your own PHP functions. Don't miss it!


 
 
>>> More PHP Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
Free Tools 
Watch our Tech Videos 
Dev Shed Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Privacy Policy 
Support 
Forums Sitemap 
Site Map 

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: