ezSQL is a widget that makes it ridiculously easy for you to use database(s) within your PHP scripts. It is fully documented with many easy to understand examples. mySQL version available, Oracle coming soon.
By : jv
ezSQL is a widget that makes it ridiculously easy for you to use database(s) within your PHP scripts.
This widget is a php file that you include at the top of your script. Then, instead of using std php database functions listed in the php manual, you use a much smaller (and easier) set of ezSQL functions.
ezSQL can dramatically increase development time and in most cases will streamline your code and make things run faster as well as making it very easy to debug and optimise your database queries.
The debug system draws a neat table showing exactly what your query was and results are.
Please read through these examples to see how easy using databases can be using ezSQL.
-------------------------------------------------------
Example 1
-------------------------------------------------------
// Select multiple records from the database..
$results = $db->get_results("SELECT name, email FROM users");
foreach ( $results as $user )
{
// Access data using object syntax
echo $user->name;
echo $user->email;
}
----------------------------------------------------
Example 2
----------------------------------------------------
// Get one row from the database..
$user = $db->get_row("SELECT name,email FROM users WHERE id = 2");
echo $user->name;
echo $user->email;
----------------------------------------------------
Example 3
----------------------------------------------------
// Get one variable from the database..
$var = $db->get_var("SELECT count(*) FROM users");
echo $var;
----------------------------------------------------
Example 4
----------------------------------------------------
// Insert into the database
$db->query("INSERT INTO users (id, name, email) VALUES (NULL,'Justin','jv@foo.com')");
----------------------------------------------------
Example 5
----------------------------------------------------
// Update the database
$db->query("UPDATE users SET name = 'Justin' WHERE id = 2)");
----------------------------------------------------
Example 6 (for debugging)
----------------------------------------------------
// Display last query and all associated results
$db->debug();
----------------------------------------------------
Example 7 (for debugging)
----------------------------------------------------
// Display the structure and contents of query results (or any variable)
$results = $db->get_results("SELECT name, email FROM users");
$db->vardump($results);
----------------------------------------------------
Example 8
----------------------------------------------------
// Get 'one column' (based on index) from a query..
$names = $db->get_col("SELECT name,email FROM users",0)
foreach ( $names as $name )
{
echo $name;
}
// Get another column from the previous (cached) query results..
$emails = $db->get_col(null,1)
foreach ( $emails as $email )
{
echo $email;
}
----------------------------------------------------
Example 9
----------------------------------------------------
// Map out the full schema of any given database..
$db->select("my_database");
foreach ( $db->get_col("SHOW TABLES",0) as $table_name )
{
$db->debug();
$db->get_results("DESC $table_name");
}
$db->debug();
Click to
Download File| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Database Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
|
|
|
|
Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads. FREE! Go There Now!
|
|
|
|
Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |