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!
|
|
|
|
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
|
|
|
|
Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
|
|
|
|
Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services. FREE! Go There Now!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
|
|
|
|
Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |