From cff41ffa408f607d4d5b466344fdc31e2814c56a Mon Sep 17 00:00:00 2001 From: Felix Wong Date: Sun, 29 Nov 2015 14:52:38 -0800 Subject: [PATCH 1/6] Create gh-pages branch via GitHub --- index.html | 57 +++++ params.json | 1 + stylesheets/github-light.css | 116 ++++++++++ stylesheets/normalize.css | 424 +++++++++++++++++++++++++++++++++++ stylesheets/stylesheet.css | 245 ++++++++++++++++++++ 5 files changed, 843 insertions(+) create mode 100644 index.html create mode 100644 params.json create mode 100644 stylesheets/github-light.css create mode 100644 stylesheets/normalize.css create mode 100644 stylesheets/stylesheet.css diff --git a/index.html b/index.html new file mode 100644 index 00000000..716c6c01 --- /dev/null +++ b/index.html @@ -0,0 +1,57 @@ + + + + + Ezsql by ezSQL + + + + + + + + + +
+

+Welcome to GitHub Pages.

+ +

This automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new gh-pages branch locally. If you’re using GitHub Desktop, simply sync your repository and you’ll see the new branch.

+ +

+Designer Templates

+ +

We’ve crafted some handsome templates for you to use. Go ahead and click 'Continue to layouts' to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved.

+ +

+Creating pages manually

+ +

If you prefer to not use the automatic generator, push a branch named gh-pages to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.

+ +

+Authors and Contributors

+ +

You can @mention a GitHub username to generate a link to their profile. The resulting <a> element will link to the contributor’s GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.

+ +

+Support or Contact

+ +

Having trouble with Pages? Check out our documentation or contact support and we’ll help you sort it out.

+ + + +
+ + + + diff --git a/params.json b/params.json new file mode 100644 index 00000000..4962e374 --- /dev/null +++ b/params.json @@ -0,0 +1 @@ +{"name":"Ezsql","tagline":"PHP class to make interacting with a database ridiculusly easy","body":"### Welcome to GitHub Pages.\r\nThis automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here [using GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/), select a template crafted by a designer, and publish. After your page is generated, you can check out the new `gh-pages` branch locally. If you’re using GitHub Desktop, simply sync your repository and you’ll see the new branch.\r\n\r\n### Designer Templates\r\nWe’ve crafted some handsome templates for you to use. Go ahead and click 'Continue to layouts' to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved.\r\n\r\n### Creating pages manually\r\nIf you prefer to not use the automatic generator, push a branch named `gh-pages` to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.\r\n\r\n### Authors and Contributors\r\nYou can @mention a GitHub username to generate a link to their profile. The resulting `` element will link to the contributor’s GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.\r\n\r\n### Support or Contact\r\nHaving trouble with Pages? Check out our [documentation](https://help.github.com/pages) or [contact support](https://github.com/contact) and we’ll help you sort it out.\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file diff --git a/stylesheets/github-light.css b/stylesheets/github-light.css new file mode 100644 index 00000000..872a6f4b --- /dev/null +++ b/stylesheets/github-light.css @@ -0,0 +1,116 @@ +/* + Copyright 2014 GitHub Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +.pl-c /* comment */ { + color: #969896; +} + +.pl-c1 /* constant, markup.raw, meta.diff.header, meta.module-reference, meta.property-name, support, support.constant, support.variable, variable.other.constant */, +.pl-s .pl-v /* string variable */ { + color: #0086b3; +} + +.pl-e /* entity */, +.pl-en /* entity.name */ { + color: #795da3; +} + +.pl-s .pl-s1 /* string source */, +.pl-smi /* storage.modifier.import, storage.modifier.package, storage.type.java, variable.other, variable.parameter.function */ { + color: #333; +} + +.pl-ent /* entity.name.tag */ { + color: #63a35c; +} + +.pl-k /* keyword, storage, storage.type */ { + color: #a71d5d; +} + +.pl-pds /* punctuation.definition.string, string.regexp.character-class */, +.pl-s /* string */, +.pl-s .pl-pse .pl-s1 /* string punctuation.section.embedded source */, +.pl-sr /* string.regexp */, +.pl-sr .pl-cce /* string.regexp constant.character.escape */, +.pl-sr .pl-sra /* string.regexp string.regexp.arbitrary-repitition */, +.pl-sr .pl-sre /* string.regexp source.ruby.embedded */ { + color: #183691; +} + +.pl-v /* variable */ { + color: #ed6a43; +} + +.pl-id /* invalid.deprecated */ { + color: #b52a1d; +} + +.pl-ii /* invalid.illegal */ { + background-color: #b52a1d; + color: #f8f8f8; +} + +.pl-sr .pl-cce /* string.regexp constant.character.escape */ { + color: #63a35c; + font-weight: bold; +} + +.pl-ml /* markup.list */ { + color: #693a17; +} + +.pl-mh /* markup.heading */, +.pl-mh .pl-en /* markup.heading entity.name */, +.pl-ms /* meta.separator */ { + color: #1d3e81; + font-weight: bold; +} + +.pl-mq /* markup.quote */ { + color: #008080; +} + +.pl-mi /* markup.italic */ { + color: #333; + font-style: italic; +} + +.pl-mb /* markup.bold */ { + color: #333; + font-weight: bold; +} + +.pl-md /* markup.deleted, meta.diff.header.from-file */ { + background-color: #ffecec; + color: #bd2c00; +} + +.pl-mi1 /* markup.inserted, meta.diff.header.to-file */ { + background-color: #eaffea; + color: #55a532; +} + +.pl-mdr /* meta.diff.range */ { + color: #795da3; + font-weight: bold; +} + +.pl-mo /* meta.output */ { + color: #1d3e81; +} + diff --git a/stylesheets/normalize.css b/stylesheets/normalize.css new file mode 100644 index 00000000..30366a6e --- /dev/null +++ b/stylesheets/normalize.css @@ -0,0 +1,424 @@ +/*! normalize.css v3.0.2 | MIT License | git.io/normalize */ + +/** + * 1. Set default font family to sans-serif. + * 2. Prevent iOS text size adjust after orientation change, without disabling + * user zoom. + */ + +html { + font-family: sans-serif; /* 1 */ + -ms-text-size-adjust: 100%; /* 2 */ + -webkit-text-size-adjust: 100%; /* 2 */ +} + +/** + * Remove default margin. + */ + +body { + margin: 0; +} + +/* HTML5 display definitions + ========================================================================== */ + +/** + * Correct `block` display not defined for any HTML5 element in IE 8/9. + * Correct `block` display not defined for `details` or `summary` in IE 10/11 + * and Firefox. + * Correct `block` display not defined for `main` in IE 11. + */ + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +main, +menu, +nav, +section, +summary { + display: block; +} + +/** + * 1. Correct `inline-block` display not defined in IE 8/9. + * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. + */ + +audio, +canvas, +progress, +video { + display: inline-block; /* 1 */ + vertical-align: baseline; /* 2 */ +} + +/** + * Prevent modern browsers from displaying `audio` without controls. + * Remove excess height in iOS 5 devices. + */ + +audio:not([controls]) { + display: none; + height: 0; +} + +/** + * Address `[hidden]` styling not present in IE 8/9/10. + * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22. + */ + +[hidden], +template { + display: none; +} + +/* Links + ========================================================================== */ + +/** + * Remove the gray background color from active links in IE 10. + */ + +a { + background-color: transparent; +} + +/** + * Improve readability when focused and also mouse hovered in all browsers. + */ + +a:active, +a:hover { + outline: 0; +} + +/* Text-level semantics + ========================================================================== */ + +/** + * Address styling not present in IE 8/9/10/11, Safari, and Chrome. + */ + +abbr[title] { + border-bottom: 1px dotted; +} + +/** + * Address style set to `bolder` in Firefox 4+, Safari, and Chrome. + */ + +b, +strong { + font-weight: bold; +} + +/** + * Address styling not present in Safari and Chrome. + */ + +dfn { + font-style: italic; +} + +/** + * Address variable `h1` font-size and margin within `section` and `article` + * contexts in Firefox 4+, Safari, and Chrome. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/** + * Address styling not present in IE 8/9. + */ + +mark { + background: #ff0; + color: #000; +} + +/** + * Address inconsistent and variable font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` affecting `line-height` in all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sup { + top: -0.5em; +} + +sub { + bottom: -0.25em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Remove border when inside `a` element in IE 8/9/10. + */ + +img { + border: 0; +} + +/** + * Correct overflow not hidden in IE 9/10/11. + */ + +svg:not(:root) { + overflow: hidden; +} + +/* Grouping content + ========================================================================== */ + +/** + * Address margin not present in IE 8/9 and Safari. + */ + +figure { + margin: 1em 40px; +} + +/** + * Address differences between Firefox and other browsers. + */ + +hr { + box-sizing: content-box; + height: 0; +} + +/** + * Contain overflow in all browsers. + */ + +pre { + overflow: auto; +} + +/** + * Address odd `em`-unit font size rendering in all browsers. + */ + +code, +kbd, +pre, +samp { + font-family: monospace, monospace; + font-size: 1em; +} + +/* Forms + ========================================================================== */ + +/** + * Known limitation: by default, Chrome and Safari on OS X allow very limited + * styling of `select`, unless a `border` property is set. + */ + +/** + * 1. Correct color not being inherited. + * Known issue: affects color of disabled elements. + * 2. Correct font properties not being inherited. + * 3. Address margins set differently in Firefox 4+, Safari, and Chrome. + */ + +button, +input, +optgroup, +select, +textarea { + color: inherit; /* 1 */ + font: inherit; /* 2 */ + margin: 0; /* 3 */ +} + +/** + * Address `overflow` set to `hidden` in IE 8/9/10/11. + */ + +button { + overflow: visible; +} + +/** + * Address inconsistent `text-transform` inheritance for `button` and `select`. + * All other form control elements do not inherit `text-transform` values. + * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. + * Correct `select` style inheritance in Firefox. + */ + +button, +select { + text-transform: none; +} + +/** + * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` + * and `video` controls. + * 2. Correct inability to style clickable `input` types in iOS. + * 3. Improve usability and consistency of cursor style between image-type + * `input` and others. + */ + +button, +html input[type="button"], /* 1 */ +input[type="reset"], +input[type="submit"] { + -webkit-appearance: button; /* 2 */ + cursor: pointer; /* 3 */ +} + +/** + * Re-set default cursor for disabled elements. + */ + +button[disabled], +html input[disabled] { + cursor: default; +} + +/** + * Remove inner padding and border in Firefox 4+. + */ + +button::-moz-focus-inner, +input::-moz-focus-inner { + border: 0; + padding: 0; +} + +/** + * Address Firefox 4+ setting `line-height` on `input` using `!important` in + * the UA stylesheet. + */ + +input { + line-height: normal; +} + +/** + * It's recommended that you don't attempt to style these elements. + * Firefox's implementation doesn't respect box-sizing, padding, or width. + * + * 1. Address box sizing set to `content-box` in IE 8/9/10. + * 2. Remove excess padding in IE 8/9/10. + */ + +input[type="checkbox"], +input[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Fix the cursor style for Chrome's increment/decrement buttons. For certain + * `font-size` values of the `input`, it causes the cursor style of the + * decrement button to change from `default` to `text`. + */ + +input[type="number"]::-webkit-inner-spin-button, +input[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Address `appearance` set to `searchfield` in Safari and Chrome. + * 2. Address `box-sizing` set to `border-box` in Safari and Chrome + * (include `-moz` to future-proof). + */ + +input[type="search"] { + -webkit-appearance: textfield; /* 1 */ /* 2 */ + box-sizing: content-box; +} + +/** + * Remove inner padding and search cancel button in Safari and Chrome on OS X. + * Safari (but not Chrome) clips the cancel button when the search input has + * padding (and `textfield` appearance). + */ + +input[type="search"]::-webkit-search-cancel-button, +input[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * Define consistent border, margin, and padding. + */ + +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/** + * 1. Correct `color` not being inherited in IE 8/9/10/11. + * 2. Remove padding so people aren't caught out if they zero out fieldsets. + */ + +legend { + border: 0; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Remove default vertical scrollbar in IE 8/9/10/11. + */ + +textarea { + overflow: auto; +} + +/** + * Don't inherit the `font-weight` (applied by a rule above). + * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. + */ + +optgroup { + font-weight: bold; +} + +/* Tables + ========================================================================== */ + +/** + * Remove most spacing between table cells. + */ + +table { + border-collapse: collapse; + border-spacing: 0; +} + +td, +th { + padding: 0; +} diff --git a/stylesheets/stylesheet.css b/stylesheets/stylesheet.css new file mode 100644 index 00000000..b5f20c23 --- /dev/null +++ b/stylesheets/stylesheet.css @@ -0,0 +1,245 @@ +* { + box-sizing: border-box; } + +body { + padding: 0; + margin: 0; + font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 16px; + line-height: 1.5; + color: #606c71; } + +a { + color: #1e6bb8; + text-decoration: none; } + a:hover { + text-decoration: underline; } + +.btn { + display: inline-block; + margin-bottom: 1rem; + color: rgba(255, 255, 255, 0.7); + background-color: rgba(255, 255, 255, 0.08); + border-color: rgba(255, 255, 255, 0.2); + border-style: solid; + border-width: 1px; + border-radius: 0.3rem; + transition: color 0.2s, background-color 0.2s, border-color 0.2s; } + .btn + .btn { + margin-left: 1rem; } + +.btn:hover { + color: rgba(255, 255, 255, 0.8); + text-decoration: none; + background-color: rgba(255, 255, 255, 0.2); + border-color: rgba(255, 255, 255, 0.3); } + +@media screen and (min-width: 64em) { + .btn { + padding: 0.75rem 1rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .btn { + padding: 0.6rem 0.9rem; + font-size: 0.9rem; } } + +@media screen and (max-width: 42em) { + .btn { + display: block; + width: 100%; + padding: 0.75rem; + font-size: 0.9rem; } + .btn + .btn { + margin-top: 1rem; + margin-left: 0; } } + +.page-header { + color: #fff; + text-align: center; + background-color: #159957; + background-image: linear-gradient(120deg, #155799, #159957); } + +@media screen and (min-width: 64em) { + .page-header { + padding: 5rem 6rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .page-header { + padding: 3rem 4rem; } } + +@media screen and (max-width: 42em) { + .page-header { + padding: 2rem 1rem; } } + +.project-name { + margin-top: 0; + margin-bottom: 0.1rem; } + +@media screen and (min-width: 64em) { + .project-name { + font-size: 3.25rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .project-name { + font-size: 2.25rem; } } + +@media screen and (max-width: 42em) { + .project-name { + font-size: 1.75rem; } } + +.project-tagline { + margin-bottom: 2rem; + font-weight: normal; + opacity: 0.7; } + +@media screen and (min-width: 64em) { + .project-tagline { + font-size: 1.25rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .project-tagline { + font-size: 1.15rem; } } + +@media screen and (max-width: 42em) { + .project-tagline { + font-size: 1rem; } } + +.main-content :first-child { + margin-top: 0; } +.main-content img { + max-width: 100%; } +.main-content h1, .main-content h2, .main-content h3, .main-content h4, .main-content h5, .main-content h6 { + margin-top: 2rem; + margin-bottom: 1rem; + font-weight: normal; + color: #159957; } +.main-content p { + margin-bottom: 1em; } +.main-content code { + padding: 2px 4px; + font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; + font-size: 0.9rem; + color: #383e41; + background-color: #f3f6fa; + border-radius: 0.3rem; } +.main-content pre { + padding: 0.8rem; + margin-top: 0; + margin-bottom: 1rem; + font: 1rem Consolas, "Liberation Mono", Menlo, Courier, monospace; + color: #567482; + word-wrap: normal; + background-color: #f3f6fa; + border: solid 1px #dce6f0; + border-radius: 0.3rem; } + .main-content pre > code { + padding: 0; + margin: 0; + font-size: 0.9rem; + color: #567482; + word-break: normal; + white-space: pre; + background: transparent; + border: 0; } +.main-content .highlight { + margin-bottom: 1rem; } + .main-content .highlight pre { + margin-bottom: 0; + word-break: normal; } +.main-content .highlight pre, .main-content pre { + padding: 0.8rem; + overflow: auto; + font-size: 0.9rem; + line-height: 1.45; + border-radius: 0.3rem; } +.main-content pre code, .main-content pre tt { + display: inline; + max-width: initial; + padding: 0; + margin: 0; + overflow: initial; + line-height: inherit; + word-wrap: normal; + background-color: transparent; + border: 0; } + .main-content pre code:before, .main-content pre code:after, .main-content pre tt:before, .main-content pre tt:after { + content: normal; } +.main-content ul, .main-content ol { + margin-top: 0; } +.main-content blockquote { + padding: 0 1rem; + margin-left: 0; + color: #819198; + border-left: 0.3rem solid #dce6f0; } + .main-content blockquote > :first-child { + margin-top: 0; } + .main-content blockquote > :last-child { + margin-bottom: 0; } +.main-content table { + display: block; + width: 100%; + overflow: auto; + word-break: normal; + word-break: keep-all; } + .main-content table th { + font-weight: bold; } + .main-content table th, .main-content table td { + padding: 0.5rem 1rem; + border: 1px solid #e9ebec; } +.main-content dl { + padding: 0; } + .main-content dl dt { + padding: 0; + margin-top: 1rem; + font-size: 1rem; + font-weight: bold; } + .main-content dl dd { + padding: 0; + margin-bottom: 1rem; } +.main-content hr { + height: 2px; + padding: 0; + margin: 1rem 0; + background-color: #eff0f1; + border: 0; } + +@media screen and (min-width: 64em) { + .main-content { + max-width: 64rem; + padding: 2rem 6rem; + margin: 0 auto; + font-size: 1.1rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .main-content { + padding: 2rem 4rem; + font-size: 1.1rem; } } + +@media screen and (max-width: 42em) { + .main-content { + padding: 2rem 1rem; + font-size: 1rem; } } + +.site-footer { + padding-top: 2rem; + margin-top: 2rem; + border-top: solid 1px #eff0f1; } + +.site-footer-owner { + display: block; + font-weight: bold; } + +.site-footer-credits { + color: #819198; } + +@media screen and (min-width: 64em) { + .site-footer { + font-size: 1rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .site-footer { + font-size: 1rem; } } + +@media screen and (max-width: 42em) { + .site-footer { + font-size: 0.9rem; } } From adc862343ce94283e923556b5c9e37910c8354ff Mon Sep 17 00:00:00 2001 From: Felix Wong Date: Sun, 29 Nov 2015 14:57:12 -0800 Subject: [PATCH 2/6] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..312d766d --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# ezSQL +PHP class to make interacting with a database ridiculusly easy From 0397922fb575c365b054db1d3761aa615590c98b Mon Sep 17 00:00:00 2001 From: Felix Wong Date: Tue, 1 Dec 2015 21:57:37 -0800 Subject: [PATCH 3/6] add help pages --- ez_sql_help.htm | 3731 +++++++++++++++++++++++++++++++++++++++ ez_sql_with_smarty.html | 185 ++ index.html | 26 +- 3 files changed, 3920 insertions(+), 22 deletions(-) create mode 100644 ez_sql_help.htm create mode 100644 ez_sql_with_smarty.html diff --git a/ez_sql_help.htm b/ez_sql_help.htm new file mode 100644 index 00000000..1b530ebc --- /dev/null +++ b/ez_sql_help.htm @@ -0,0 +1,3731 @@ + + + + + +Introduction + + + + + + +
+ +

ezSQL Overview download ez_sql.zip
+To email the creator: justin_at_jvmultimedia_dot_com

+ +

 

+ +

·         +ezSQL is a widget that +makes it very fast and easy for you to use database(s) within your PHP scripts +( mySQL / Oracle8/9 / InterBase/FireBird / PostgreSQL / MS-SQL / SQLite / +SQLite c++).

+ +

 

+ +

·         +It is one php file that you include at the +top of your script. Then, instead of using standard php database functions +listed in the php manual, you use a much smaller (and easier) set of +ezSQL  functions.

+ +

 

+ +

·         +It automatically caches query results and +allows you to use easy to understand functions to manipulate and extract them +without causing extra server overhead

+ +

 

+ +

·         +It has excellent debug functions making it +lightning-fast to see what’s going on in your SQL code

+ +

 

+ +

·         +Most ezSQL functions can return results as +Objects, Associative Arrays, or Numerical Arrays

+ +

 

+ +

·         +It can +dramatically decrease 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.

+ +

 

+ +

·         +It is a +small class and will not add very much overhead to your website.

+ +

 

+ +

Note: It is assumed that +you are familiar with PHP, basic Database concepts and basic SQL constructs. +Even if you are a complete beginner ezSQL can help you once you have read and +understood this +tutorial.

+ +

 

+ +
+ +

 

+ +

 

+ +
+ +

 

+ +

 

+ +

Quick Examples..

+ +

Note: +In all these examples no other code is required other than including ez_sql.php

+ +

 

+ +

            +----------------------------------------------------

+ +

Example 1

+ +

----------------------------------------------------

+ +

 

+ +

// Select multiple records from the database +and print them out..

+ +

$users = $db->get_results("SELECT +name, email FROM users");

+ +

 

+ +

foreach ( $users as $user )

+ +

{

+ +

            +// Access +data using object syntax

+ +

            +echo $user->name;

+ +

            +echo $user->email;

+ +

}

+ +

 

+ +

----------------------------------------------------

+ +

Example 2

+ +

----------------------------------------------------

+ +

 

+ +

// Get one row from the database and print it +out..

+ +

$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 and print +it out..

+ +

$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
+ +

----------------------------------------------------

+ +

 

+ +

// Display last query and all associated +results

+ +

$db->debug();

+ +

 

+ +

 

+ +

----------------------------------------------------

+ +
Example 7
+ +

----------------------------------------------------

+ +

 

+ +

// Display the structure and contents of any +result(s) .. or any variable

+ +

$results = $db->get_results("SELECT +name, email FROM users");

+ +

 

+ +

$db->vardump($results);

+ +

 

+ +

 

+ +

----------------------------------------------------

+ +
Example 8
+ +

----------------------------------------------------

+ +

 

+ +

// Get 'one column' (based on column index) and +print it out..

+ +

$names = $db->get_col("SELECT +name,email FROM users",0)

+ +

 

+ +

foreach ( $names as $name )

+ +

{

+ +

            +echo $name;

+ +

}

+ +

 

+ +

----------------------------------------------------

+ +
Example 9
+ +

----------------------------------------------------

+ +

 

+ +

// Same as above ‘but quicker’

+ +

foreach ( $db->get_col("SELECT +name,email FROM users",0) as $name )

+ +

{

+ +

            +echo $name;

+ +

}

+ +

 

+ +

----------------------------------------------------

+ +
Example 10
+ +

----------------------------------------------------

+ +

 

+ +

// Map out the full schema of any given +database and print it out..

+ +

 

+ +

$db->select("my_database");

+ +

 

+ +

foreach ( $db->get_col("SHOW +TABLES",0) as $table_name )

+ +

{

+ +

 

+ +

            +$db->debug();

+ +

            +$db->get_results("DESC $table_name");

+ +

 

+ +

}

+ +

 

+ +

$db->debug();

+ +
+ +

 

+ +

 

+ +

 

+ +

 

+ +
+ +

 

+ +

 

+ +

Introduction

+ +

 

+ +

When working with databases most of the time you will want to do +one of four types of basic operations.

+ +

 

+ +

1.      Perform a query such +as Insert or Update (without results)

+ +

2.      Get a single variable +from the database

+ +

3.      Get a single row from +the database

+ +

4.      Get a list of results +from the database

+ +

 

+ +

ezSQL wraps up these four basic actions into four very easy to +use functions.

+ +

 

+ +

bool     $db->query(query)

+ +

var       $db->get_var(query)

+ +

mixed $db->get_row(query)

+ +

mixed $db->get_results(query)

+ +

 

+ +

With ezSQL these four functions are all you will need 99.9% of +the time. Of course there are also some other useful functions but we will get +into those later.

+ +

 

+ +

Important Note: If you use ezSQL inside a function you write, you will +need to put global $db; at the top.

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

Installation

+ +

 

+ +

To install ezSQL download, unzip and install the contents of ez_sql.zip into +the same directory within your web server.

+ +

 

+ +

Put the following at the top of your script:

+ +

 

+ +

            // Include ezSQL core

+ +

            include_once "ez_sql_core.php";

+ +

 

+ +

            // Include ezSQL database specific +component (in this case mySQL)

+ +

            include_once +"ez_sql_mysql.php";

+ +

 

+ +

            // Initialise database object and +establish a connection

+ +

            // at the same time - db_user / +db_password / db_name / db_host

+ +

            $db = new +ezSQL_mysql('db_user','db_password','db_name','db_host');

+ +

 

+ +

 

+ +

Note: On most systems localhost will be +fine for the dbhost value. If you are unsure about any of the above settings +you should contact your provider or look through your providers documentation.

+ +

 

+ +

If you are running on a local machine and have +just installed mySQL for the first time, you can probably leave the user name +and password empty ( i.e.  = “”) until you set up a mySQL user account.

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

Running the ezSQL demo

+ +

 

+ +

Once you have installed ezSQL as described +above you can see it in action by running ez_demo.php via your web browser. To +do this simply go to..

+ +

 

+ +

http://yourserver.com/install_path/mysql/demo.php

+ +

 

+ +

If you are running your web server on your +local machine this will be..

+ +

 

+ +

http://127.0.0.1/install_path/mysql/demo.php

+ +

 

+ +

What the demo does… is use ezSQL functions to +map out the table structure of your database (i.e the database you specified at +the top of ez_sql.php). You will be surprised how little code is required to do +this when using ezSQL. I have included it here so you can get a quick feel for +the compactness and speed of ezSQL.

+ +

 

+ +

<?php

+ +

 

+ +

             // Include ezSQL core

+ +

             include_once "ez_sql_core.php";

+ +

 

+ +

             // Include ezSQL database +specific component

+ +

             include_once +"ez_sql_mysql.php";

+ +

 

+ +

             // Initialise database object and +establish a connection

+ +

             // at the same time - db_user / +db_password / db_name / db_host

+ +

             $db = new +ezSQL_mysql('db_user','db_password','db_name','db_host');

+ +

 

+ +

            +$my_tables = $db->get_results("SHOW TABLES",ARRAY_N);

+ +

            +$db->debug();

+ +

            +

+ +

            +foreach ( $my_tables as $table )

+ +

            +{

+ +

                        +$db->get_results("DESC $table[0]");

+ +

                        +$db->debug();

+ +

            +}

+ +

            +

+ +

?>

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

The ezSQL demo explained

+ +

 

+ +

<?php

+ +

This is the standard way to start php +executing within your web page.

+ +

 

+ +

include_once “ez_sql.php”;

+ +

This is how you include ezSQL in your script. +Normally you include it at the top of your script and from that point forward +you have access to any ezSQL function.

+ +

 

+ +

            +$my_tables = $db->get_results(“SHOW TABLES”,ARRAY_N);

+ +

get_results() is how you +get ‘a list’ of things from the database using ezSQL. The list is returned as +an array. In this case the std mySQL command  of ‘SHOW TABLES’ is called +and the resulting list is stored in a  newly created array $my_tables.

+ +

 

+ +

When using $db->get_results(), if there are +any results, they are always returned as multi-dimensional array. The first +dimension is a numbered index. Each of the numbered indexes is either an +object, associative array or numerical array containing all the values for ‘one +row’.

+ +

 

+ +

For example using the switch ARRAY_A would +produce an array that looked something like this.

+ +

 

+ +

            +$users += $db->get_results(“SELECT id,name FROM users”,ARRAY_A);

+ +

 

+ +

$users[0] = array +(“id” => “1”, “name” => “Amy”);

+ +

$users[1] = array +(“id” => “2”, “name” => “Tyson”);

+ +

 

+ +

If you wanted a numerical array use the switch +ARRAY_N.

+ +

 

+ +

            +$users += $db->get_results(“SELECT id,name FROM users”,ARRAY_N);

+ +

 

+ +

$users[0] = array (0 +=> “1”, 1 => “Amy”);

+ +

$users[1] = array (0 +=> “2”, 1 => “Tyson”);

+ +

 

+ +

If you wanted an object (which is the default +option) you don’t need a switch..

+ +

 

+ +

$users = +$db->get_results(“SELECT id,name FROM users”);

+ +

 

+ +

$users[0]->id = +“1”;

+ +

$users[0]->name = +“Amy”;

+ +

$users[1]->id = +“2”;

+ +

$users[1]->name = +“Tyson”;

+ +

 

+ +

Results returned as an object make it very +easy to work with database results using the numerous array functions that php +offers. For example, to loop through results returned as an object all one +needs to do is..

+ +

 

+ +

$users = +$db->get_results(“SELECT id,name FROM users”);

+ +

 

+ +

                                    +foreach( $users as $user )

+ +

                                    +{

+ +

                                                +echo $user->id;

+ +

                                                +echo $user->name;

+ +

                                    +}

+ +

 

+ +

                        +If you are 100% sure that there will be results you can skip a step and do +this..

+ +

 

+ +

                                    +foreach( $db->get_results(“SELECT id,name FROM users”) as $user )

+ +

                                    +{

+ +

                                                +echo $user->id;

+ +

                                                +echo $user->name;

+ +

                                    +}

+ +

 

+ +

                        +If you don’t know whether there will be results or not you can do this..

+ +

 

+ +

If ( $users= +$db->get_results(“SELECT id,name FROM users”) )

+ +

{

+ +

                                                +foreach( $users as $user )

+ +

                                                +{

+ +

                                                            +echo $user->id;

+ +

                                                            +echo $user->name;

+ +

            +}

+ +

}

+ +

else

+ +

{

+ +

            +echo “No results”;

+ +

}

+ +

 

+ +

$db->debug();

+ +

This function prints the +most recently called sql query along with a well formatted table containing any +results that the query generated (if any) and the column info.

+ +

 

+ +

foreach ( $my_tables as +$table)

+ +

This is the standard way to easily loop through an array +in php. In this case the array $my_tables was created with the ezSQL command +$db->get_results(“SHOW TABLES”,ARRAY_N). Because of the ARRAY_N switch the +results are returned as a numerical array.

+ +

 

+ +

The resulting array +will look something like..

+ +

 

+ +

$my_tables[0] = array +(0 => “users”);

+ +

$my_tables[1] = array +(0 => “products”);

+ +

$my_tables[2] = array +(0 => “guestbook”);

+ +

 

+ +

            +{

+ +

The foreach is looping through each primary +element of $my_tables[n] which are in turn numerical arrays, with the format +like so..

+ +

 

+ +

            +array(0 => “value”, 1 => “value”, etc.);

+ +

 

+ +

Thus, during the foreach loop of $my_tables we +have access to the value of the first column like so:

+ +

 

+ +

            +foreach ($my_tables as $table)

+ +

            +{

+ +

                        +echo $table[0];

+ +

            +}

+ +

            +

+ +

If we did the same +thing using an associative array it might look like this..

+ +

 

+ +

            +$users = $db->get_results(“SELECT id,name FROM users”,ARRAY_A);

+ +

 

+ +

            +foreach ( $users as $user )

+ +

            +{

+ +

                        +echo $user[‘id’];

+ +

                        +echo $user[‘name’];

+ +

            +}

+ +

 

+ +

But if there were no results foreach might +generate a warning. So a safer way to do the above is..

+ +

 

+ +

            +if ( $users = $db->get_results(“SELECT id,name FROM users”,ARRAY_A))

+ +

            +{

+ +

                        +foreach ( $users as $user )

+ +

                        +{

+ +

                                    +echo $user[‘id’];

+ +

                                    +echo $user[‘name’];

+ +

                        +}

+ +

            +}

+ +

            +else

+ +

            +{

+ +

                        +echo “No Users”:

+ +

            +}

+ +

 

+ +

This works because if +no results are returned then get_results() returns false.

+ +

 

+ +

                        +$db->get_results(“DESC $table[0]”);

+ +

This database query is nested within the +foreach loop. Note that we are using the results of the previous call to make a +new call. Traditionally you would have to be concerned about using different +db_resource identifiers in a case like this but ezSQL takes care of that for you, +making it very easy to nest database queries.

+ +

 

+ +

You may be wondering why I have used a +numerical array output and not object or associative array. The reason is +because in this case I do not know what the name of the first column will be. +So I can make sure that I can always get its value by using numerical array +output and targeting the first column by element [0].

+ +

 

+ +

FYI: The SQL command SHOW TABLES always names +the first column a different value depending on the database being used. If the +database was named users the column would be called Tables_in_users +if the database was called customers the column would be called Tables_in_customers +and so on.

+ +

 

+ +

 

+ +

                        +$db->debug();

+ +

This function will always print the last query +and its results (if any) to the browser. In this case it will be for the above +query..

+ +

 

+ +

            +$db->get_results(“DESC $table[0]”);

+ +

 

+ +

You may have noticed that the above +get_results function is not assigning a value. (i.e. $var = val). This is +because even if you do not assign the output value of any ezSQL function the +query results are always stored and made ready for any ezSQL function to use. +In this case $db->debug() is displaying the stored results. Then, by calling +any ezSQL function using a null query you will be accessing the stored +results from the last query. Here is a more detailed +example.           

+ +

 

+ +

Users Table..

+ +

amy, amy@foo.com

+ +

tyson, tyson@foo.com

+ +

 

+ +

            +// Any +ezSQL function will store query results..

+ +

            +$users = $db->get_results(“SELECT name,email FROM users”);

+ +

 

+ +

            +// This gets a variable from the above results (offset by $x = 1, $y = 1).

+ +

            +echo $db->get_var(null,1,1);

+ +

 

+ +

            +// Note: Because a null query is passed to get_var it uses results from +the previous query.

+ +

                        +

+ +

Output: +tyson@foo.com        

+ +

 

+ +

            +}

+ +

            +This closes the foreach loop

+ +

 

+ +

?>

+ +

This stops php executing code

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

ezSQL functions

+ +

 

+ +

$db->get_results -- get multiple row result set from the database (or +previously cached results)

+ +

$db->get_row -- get one row from the database (or previously cached +results)

+ +

$db->get_col -- get one column from query (or previously cached results) +based on column offset

+ +

$db->get_var -- get one variable, from one row, from the database (or +previously cached results)

+ +

$db->query -- send a query to the database (and if any results, cache +them)

+ +

$db->debug -- print last sql query and +returned results (if any)

+ +

$db->vardump -- print the contents and structure of any variable

+ +

$db->select -- select a new database to work with

+ +

$db->get_col_info -- get information about one or all columns such as column +name or type

+ +

$db->hide_errors -- turn ezSQL error output to browser off

+ +

$db->show_errors -- turn ezSQL error output to browser on

+ +

$db->escape -- Format a string correctly to stop accidental mal formed +queries under all PHP conditions

+ +

$db = new db -- Initiate new db object.

+ +

 

+ +

ezSQL variables

+ +
+ +

 

+ +

$db->num_rows – Number of rows that were returned (by the database) for +the last query (if any)

+ +

$db->insert_id -- ID generated from the AUTO_INCRIMENT of the previous +INSERT operation (if any)

+ +

$db->rows_affected -- Number of rows affected (in the database) by the +last INSERT, UPDATE or DELETE (if any)

+ +

$db->num_queries -- Keeps track of exactly how many 'real' (not cached) +queries were executed during the lifetime of the current script

+ +

$db->debug_all – If set to true (i.e. $db->debug_all = true;) Then it +will print out ALL queries and ALL results of your script.

+ +

$db->cache_dir – Path to mySQL caching dir.

+ +

$db->cache_queries – Boolean flag (see mysql/disk_cache_example.php)

+ +

$db->cache_inserts – Boolean flag (see mysql/disk_cache_example.php)

+ +

$db->use_disk_cache – Boolean flag (see mysql/disk_cache_example.php)

+ +

$db->cache_timeout – Number in hours (see mysql/disk_cache_example.php)

+ +

 

+ +

 

+ +
+ +

 

+ +

 

+ +

$db = new db

+ +

 

+ +

$db = new db -- Initiate new db object. Connect to a +database server. Select a database.

+ +

 

+ +

Description

+ +

 

+ +

$db = new db(string username, string password, string +database name, string database host)

+ +

 

+ +

Does three things. (1) Initiates a new db object. (2) +Connects to a database server. (3) Selects a database. You can also re-submit +this command if you would like to initiate a second db object. This is +interesting because you can run two concurrent database connections at the same +time. You can even connect to two different servers at the same time if you +want to.

+ +

 

+ +

Note: For the sake of efficiency it is recommended that you +only run one instance of the db object and use $db->select to +switch between different databases on the same server connection.

+ +

 

+ +

Example

+ +

 

+ +

          +// +Initiate new database object..

+ +

$db2 = new db(”user_name”, ”user_password”, +”database_name”, “database_host”);

+ +
+ +

 

+ +

            +// +Perform some kind of query..

+ +

            +$other_db_tables = $db2->get_results(“SHOW TABLES”);

+ +

 

+ +

            +// You can +still query the database you were already connected to..

+ +

            +$existing_connection_tables = $db->get_results(“SHOW TABLES”);

+ +

 

+ +

            +// Print +the results from both of these queries..

+ +

            +$db->debug();

+ +

            +$db2->debug();

+ +

 

+ +

 

+ +
+ +

 

+ +

 

+ +

$db->select

+ +

 

+ +

$db->select -- select a new database to work with

+ +

 

+ +

Description

+ +

 

+ +

bool $db->select(string database name)

+ +

 

+ +

$db->select() selects a new database to work with using the current +database connection as created with $db = new db.

+ +

 

+ +
Example
+ +

 

+ +

            +// Get a +users name from the user’s database (as initiated with $db = new db)..

+ +

$user_name = $db->get_var(“SELECT name FROM +users WHERE id = 22”) ;

+ +

 

+ +

          +// Select +the database stats..

+ +

$db->select(“stats”);

+ +

 

+ +

            +// Get a +users name from the user’s database..

+ +

$total_hours = $db->get_var(“SELECT +sum(time_logged_in) FROM user_stats WHERE user = ‘$user_name’”) ;

+ +

 

+ +

          +// Re-select +the ‘users’ database to continue working as normal..

+ +

$db->select(“users”);

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->query

+ +

 

+ +

$db->query -- send a query to the database (and if any +results, cache them)

+ +

 

+ +

Description

+ +

 

+ +

bool $db->query(string query)

+ +

 

+ +

$db->query() sends a query to the currently selected database. It +should be noted that you can send any type of query to the database using this +command. If there are any results generated they will be stored and can be +accessed by any ezSQL function as long as you use a null query. If there are +results returned the function will return true if no results the return +will be false

+ +

 

+ +

Example 1

+ +

 

+ +

            +// Insert +a new user into the database..

+ +

$db->query(“INSERT INTO users (id,name) VALUES (1,’Amy’)”) ;

+ +

 

+ +

Example 2

+ +

 

+ +

            +// Update +user into the database..

+ +

$db->query(“UPDATE users SET name = ‘Tyson’ WHERE id = 1”) ;

+ +

 

+ +

Example 3

+ +

 

+ +

            +// Query +to get full user list..

+ +

$db->query(“SELECT name,email FROM users”) ;

+ +

 

+ +

            +// Get the +second row from the cached results by using a null query..

+ +

$user_details = $db->get_row(null, OBJECT,1);

+ +

 

+ +

            +// Display +the contents and structure of the variable $user_details..

+ +

$db->vardump($user_details);

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->get_var

+ +

 

+ +

$db->get_var -- get one variable, from one row, from the +database (or previously cached results)

+ +

 

+ +

Description

+ +

 

+ +

var $db->get_var(string query / null [,int column +offset[, int row offset])

+ +

 

+ +

$db->get_var() gets one single variable from the database or previously +cached results. This function is very useful for evaluating query results +within logic statements such as if or switch. If the query +generates more than one row the first row will always be used by default. If +the query generates more than one column the leftmost column will always be +used by default. Even so, the full results set will be available within the +array $db->last_results should you wish to use them.

+ +

 

+ +

Example 1

+ +

 

+ +

            +// Get +total number of users from the database..

+ +

$num_users = $db->get_var(“SELECT count(*) FROM +users”) ;

+ +

 

+ +

Example 2

+ +

 

+ +

            +// Get a +users email from the second row of results (note: col 1, row 1 [starts at 0])..

+ +

$user_email = $db->get_var(“SELECT name, email +FROM users”,1,1) ;

+ +

 

+ +

            +// Get the +full second row from the cached results (row = 1 [starts at 0])..

+ +

$user = $db->get_row(null,OBJECT,1);

+ +

 

+ +

            +// Both are the +same value..

+ +

            +echo $user_email;

+ +

            +echo $user->email;

+ +

 

+ +

Example 3

+ +

 

+ +

            +// Find +out how many users there are called Amy..

+ +

if ( $n = $db->get_var(“SELECT count(*) FROM +users WHERE name = ‘Amy’”) )

+ +

{

+ +

            +// If +there are users then the if clause will evaluate to true. This is useful +because

+ +

// we can extract a +value from the DB and test it at the same time.

+ +

                        +echo “There +are $n users called Amy!”;

+ +

}

+ +

else

+ +

{

+ +

// If there are no +users then the if will evaluate to false..

+ +

                        +echo “There +are no users called Amy.”;

+ +

}

+ +

 

+ +

Example 4

+ +

 

+ +

          +// Match a +password from a submitted from a form with a password stored in the DB

+ +

if ( $pwd_from_form == $db->get_var(“SELECT pwd FROM users +WHERE name = ‘$name_from_form’”) )

+ +

{

+ +

            +// Once +again we have extracted and evaluated a result at the same time..

+ +

                        +echo “Congratulations +you have logged in.”;

+ +

}

+ +

else

+ +

{

+ +

            +// If has +evaluated to false..

+ +

                        +echo “Bad +password or Bad user ID”;

+ +

}

+ +
+ +

 

+ +

 

+ +
+ +

 

+ +
+
+ +

$db->get_row

+ +

 

+ +

$db->get_row -- get one row from the database (or previously +cached results)

+ +

 

+ +

Description

+ +

 

+ +

object $db->get_ row(string query / null [, OBJECT +/ ARRAY_A / ARRAY_N [, int row offset]])

+ +

 

+ +

$db->get_row() gets a single row from the database or cached results. If +the query returns more than one row and no row offset is supplied the first row +within the results set will be returned by default. Even so, the full results +will be cached should you wish to use them with another ezSQL query.

+ +

 

+ +
Example 1
+ +

 

+ +

            +// Get a users name and email from the database and extract it into an object +called user..

+ +

$user = $db->get_row(“SELECT name,email FROM +users WHERE id = 22”) ;

+ +

 

+ +

            +// Output +the values..

+ +

            +echo “$user->name has the email of $user->email”;

+ +

 

+ +

 

+ +

            +Output:

+ +

                        +Amy has the email of amy@foo.com

+ +

 

+ +

Example 2

+ +

 

+ +

            // Get users name and +date joined as associative array

+ +

// (Note: we must specify the row offset index +in order to use the third argument)

+ +

            $user = +$db->get_row(“SELECT name, UNIX_TIMESTAMP(my_date_joined) as date_joined +FROM users WHERE id = 22”,ARRAY_A) ;

+ +

 

+ +

            +// Note +how the unix_timestamp command is used with as this will ensure that the +resulting data will be easily

+ +

// accessible via the created object or +associative array. In this case $user[‘date_joined’] (object would be +$user->date_joined)

+ +

            +echo $user[‘name’] . “ joined us on ” . date(“m/d/y”,$user[‘date_joined’]);

+ +

 

+ +

            +Output:

+ +

                        +Amy joined us on 05/02/01

+ +

 

+ +

Example 3

+ +

 

+ +

            // Get second row of +cached results.

+ +

            $user = +$db->get_row(null,OBJECT,1) ;

+ +

 

+ +

            // Note: Row offset +starts at 0

+ +

            +echo “$user->name joined us on ” . date(“m/d/y”,$user->date_joined);

+ +

 

+ +

 

+ +

            +Output:

+ +

                        +Tyson joined us on 05/02/02

+ +

 

+ +

Example 4

+ +

 

+ +

            // Get one row as a +numerical array..

+ +

            $user = +$db->get_row(“SELECT name,email,address FROM users WHERE id = 1”,ARRAY_N);

+ +

 

+ +

            // Output the results +as a table..

+ +

            echo “<table>”;

+ +

 

+ +

            +for ( $i=1; $i <= count($user); $i++ )

+ +

            +{

+ +

                        +echo +“<tr><td>$i</td><td>$user[$I]</td></tr>”;

+ +

            +}

+ +

 

+ +

            +echo “</table>”;

+ +

 

+ +

 

+ +

            +Output:

+ +

 

+ +

1                    +amy

+ +

2                    +amy@foo.com

+ +

3                    +123 +Foo Road

+ +

 

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->get_results

+ +

 

+ +

$db->get_results – get multiple row result set from the +database (or previously cached results)

+ +

 

+ +

Description

+ +

 

+ +

array $db->get_results(string query / null [, +OBJECT / ARRAY_A / ARRAY_N ] )

+ +

 

+ +

$db->get_row() gets multiple rows of results from the database based on query +and returns them as a multi dimensional array. Each element of the array +contains one row of results and can be specified to be either an object, +associative array or numerical array. If no results are found then the function +returns false enabling you to use the function within logic statements such as if.

+ +

 

+ +

Example 1 – +Return results as objects (default)

+ +

 

+ +

Returning results as an object is the quickest +way to get and display results. It is also useful that you are able to put +$object->var syntax directly inside print statements without having to worry +about causing php parsing errors.

+ +

 

+ +

          +// Extract +results into the array $users (and evaluate if there are any results at the +same time)..

+ +

if ( $users = $db->get_results(“SELECT name, email +FROM users”) +)

+ +

{

+ +

            +// Loop +through the resulting array on the index $users[n]

+ +

                        +foreach ( $users as $user )

+ +

                        +{

+ +

                                    +// Access +data using column names as associative array keys

+ +

                                    +echo “$user->name - $user->email<br>”;

+ +

                        +}

+ +

}

+ +

else

+ +

{

+ +

            +// If no +users were found then if evaluates to false..

+ +

                        +echo “No +users found.”;

+ +

}

+ +

 

+ +

 

+ +

            +Output:

+ +

            +Amy - amy@hotmail.com     

+ +

            +Tyson - tyson@hotmail.com

+ +

 

+ +

Example 2 – +Return results as associative array

+ +

 

+ +

Returning results as an associative array is +useful if you would like dynamic access to column names. Here is an example.

+ +

 

+ +

          +// Extract +results into the array $dogs (and evaluate if there are any results at the same +time)..

+ +

if ( $dogs = $db->get_results(“SELECT breed, owner, +name FROM dogs”, ARRAY_A) )

+ +

{

+ +

            +// Loop +through the resulting array on the index $dogs[n]

+ +

                        +foreach ( $dogs as $dog_detail )

+ +

                        +{

+ +

 

+ +

                        +// Loop +through the resulting array

+ +

                                    +foreach ( $dogs_detail as $key => $val )

+ +

                                    +{

+ +

                                                +// Access +and format data using $key and $val pairs..

+ +

                                                +echo “<b>” . ucfirst($key) . “</b>: $val<br>”;

+ +

                                    +}

+ +

 

+ +

                        +// Do a P +between dogs..

+ +

                                    +echo “<p>”;

+ +

                        +}

+ +

}

+ +

else

+ +

{

+ +

            +// If no +users were found then if evaluates to false..

+ +

                        +echo “No +dogs found.”;

+ +

}

+ +

 

+ +

 

+ +

            +Output:

+ +

            +Breed: Boxer

+ +

            +Owner: Amy

+ +

            +Name: Tyson

+ +

 

+ +

            +Breed: Labrador

+ +

            +Owner: Lee

+ +

            +Name: Henry

+ +

 

+ +

            +Breed: Dachshund

+ +

            +Owner: Mary

+ +

            +Name: Jasmine

+ +

 

+ +

 

+ +

Example 3 – +Return results as numerical array

+ +

 

+ +

            +Returning +results as a numerical array is useful if you are using completely dynamic +queries with varying column

+ +

names but still need a +way to get a handle on the results. Here is an example of this concept in use. +Imagine that this

+ +

script was responding to +a form with $type being submitted as either ‘fish’ or ‘dog’.

+ +

 

+ +

                        +// Create +an associative array for animal types..

+ +

                        +$animal = array ( “fish” => “num_fins”, “dog” => “num_legs” );

+ +

 

+ +

                        +// Create +a dynamic query on the fly..

+ +

                        +if ( $results = $db->(“SELECT $animal[$type] FROM $type”,ARRAY_N))

+ +

                        +{

+ +

                                    +foreach ( $results as $result )

+ +

                                    +{

+ +

                                                +echo “$result[0]<br>”;

+ +

                                    +}

+ +

                        +}

+ +

                        +else

+ +

                        +{

+ +

                                    +echo “No $animal\s!”;

+ +

                        +}

+ +

 

+ +

                        +            Output:

+ +

                                                +4

+ +

                                                +4

+ +

                                                +4

+ +

 

+ +

            +            +Note: The dynamic query would be look like one of the following...

+ +

 

+ +

·         +SELECT +num_fins FROM fish

+ +

·         +SELECT +num_legs FROM dogs

+ +

 

+ +

                        +It would be easy to see which it was by using $db->debug(); after the +dynamic query call.

+ +

 

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->debug

+ +

 

+ +

$db->debug – print +last sql query and returned results (if any)

+ +

 

+ +

Description

+ +

 

+ +

$db->debug(void)

+ +

 

+ +

$db->debug() prints last sql query and its results (if any)

+ +

 

+ +

 

+ +

Example 1

+ +

 

+ +

If you need to know what your last query was and +what the returned results are here is how you do it.

+ +

 

+ +

          +// Extract +results into the array $users..

+ +

$users = $db->get_results(“SELECT name, email +FROM users”);

+ +

 

+ +

// See what just happened!

+ +

$db->debug();

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->vardump

+ +

 

+ +

$db->vardump – print the contents and structure of any +variable

+ +

 

+ +

Description

+ +

 

+ +

$db->vardump(void)

+ +

 

+ +

$db->vardump() prints the contents and structure of any variable. It does not matter what the structure is be it an object, +associative array or numerical array.

+ +

 

+ +

Example 1

+ +

 

+ +

If you need to know what value and structure any +of your results variables are here is how you do it.

+ +

 

+ +

          +// Extract +results into the array $users..

+ +

$users = $db->get_results(“SELECT name, email +FROM users”);

+ +

 

+ +

// View the contents and structure of $users

+ +

$db->vardump($users);

+ +
+ +

 

+ +

 

+ +
+ +

 

+ +

 

+ +

$db->get_col

+ +

 

+ +

$db->get_col – get +one column from query (or previously cached results) based on column offset

+ +

 

+ +

Description

+ +

 

+ +

$db->get_col( string query / null [, int column offset] )

+ +

 

+ +

$db->get_col() extracts one column as one dimensional array based on a +column offset. If no offset is supplied the offset will defualt to column 0. +I.E the first column. If a null query is supplied the previous query results +are used.

+ +

 

+ +

Example 1

+ +

 

+ +

          +// Extract +list of products and print them out at the same time..

+ +

foreach ( $db->get_col(“SELECT product FROM +product_list”) as $product)

+ +

{

+ +

            +echo $product;

+ +

}

+ +

 

+ +

Example 2 – +Working with cached results

+ +

 

+ +

          +// Extract +results into the array $users..

+ +

$users = $db->get_results(“SELECT * FROM users”);

+ +

 

+ +

// Work out how many columns have been +selected..

+ +

$last_col_num = $db->num_cols - 1;

+ +

 

+ +

// Print the last column of the query using +cached results..

+ +

foreach ( $db->get_col(null, $last_col_num) as +$last_col )

+ +

{

+ +

            +echo $last_col;

+ +

}

+ +

 

+ +

         

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->get_col_info

+ +

 

+ +

$db->get_col_info - get information about one or all +columns such as column name or type

+ +

 

+ +

Description

+ +

 

+ +

$db->get_col_info(string info-type[, int column offset])

+ +

 

+ +

$db->get_col_info()returns meta information about +one or all columns such as column name or type. If no information type is +supplied then the default information type of name is used. If no column +offset is supplied then a one dimensional array is returned with the +information type for ‘all columns’. For access to the full meta information for +all columns you can use the cached variable $db->col_info

+ +

 

+ +

Available Info-Types

+ +

 

+ +

mySQL

+ +

 

+ +

·         +name - +column name

+ +

·         +table - +name of the table the column belongs to

+ +

·         +max_length - +maximum length of the column

+ +

·         +not_null - 1 +if the column cannot be NULL

+ +

·         +primary_key - 1 +if the column is a primary key

+ +

·         +unique_key - 1 +if the column is a unique key

+ +

·         +multiple_key - 1 +if the column is a non-unique key

+ +

·         +numeric - 1 +if the column is numeric

+ +

·         +blob - 1 +if the column is a BLOB

+ +

·         +type - +the type of the column

+ +

·         +unsigned - 1 +if the column is unsigned

+ +

·         +zerofill - 1 +if the column is zero-filled

+ +

 

+ +

ibase

+ +

 

+ +

·         +name - +column name 

+ +

·         +type - +the type of the column

+ +

·         +length - +size of column

+ +

·         +alias - +undocumented

+ +

·         +relation - +undocumented

+ +

 

+ +

MS-SQL / Oracle / Postgress

+ +

 

+ +

·         +name - +column name 

+ +

·         +type - +the type of the column

+ +

·         +length - +size of column

+ +

 

+ +

SQLite

+ +

 

+ +

·         +name - +column name 

+ +

 

+ +

Example 1

+ +

 

+ +

          +// Extract +results into the array $users..

+ +

$users = $db->get_results(“SELECT id, name, +email FROM users”);

+ +

 

+ +

// Output the name for each column type

+ +

foreach ( $db->get_col_info(“name”)  as +$name )

+ +

{

+ +

            +echo “$name<br>”;

+ +

}

+ +

 

+ +

            +Output:

+ +

            +            +id

+ +

                        +name

+ +

                        +email

+ +

 

+ +

 

+ +

Example 2

+ +

 

+ +

          +// Extract +results into the array $users..

+ +

$users = $db->get_results(“SELECT id, name, +email FROM users”);

+ +

 

+ +

          +// View +all meta information for all columns..

+ +

          +$db->vardump($db->col_info);

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->hide_errors

+ +

 

+ +

$db->hide_errors – +turn ezSQL error output to browser off

+ +

 

+ +

Description

+ +

 

+ +

$db->hide_errors( void )

+ +

 

+ +

$db->hide_errors() stops error output from being printed to the web client. +If you would like to stop error output but still be able to trap errors for +debugging or for your own error output function you can make use of the global +error array $EZSQL_ERROR.

+ +

 

+ +

Note: If there were no errors then the global error array +$EZSQL_ERROR will evaluate to false. If there were one or more errors then it +will have  the following structure. Errors are added to the array in order +of being called.

+ +

 

+ +

$EZSQL_ERROR[0] = Array

+ +

(

+ +

                +[query] => SOME BAD QUERY

+ +

                +[error_str] => You have an error in your SQL syntax near ‘SOME BAD QUERY' at +line 1

+ +

)

+ +

 

+ +

$EZSQL_ERROR[1] = Array

+ +

(

+ +

                +[query] => ANOTHER BAD QUERY

+ +

                +[error_str] => You have an error in your SQL syntax near ‘ANOTHER BAD QUERY' +at line 1

+ +

)

+ +

 

+ +

$EZSQL_ERROR[2] = Array

+ +

(

+ +

                +[query] => THIRD BAD QUERY

+ +

                +[error_str] => You have an error in your SQL syntax near ‘THIRD BAD QUERY' +at line 1

+ +

)

+ +

 

+ +

Example 1

+ +

 

+ +

          +// Using a +custom error function

+ +

$db->hide_errors();

+ +

 

+ +

// Make a silly query that will produce an +error

+ +

$db->query(“INSERT INTO my_table A BAD QUERY +THAT GENERATES AN ERROR”);

+ +

 

+ +

// And another one, for good measure

+ +

$db->query(“ANOTHER BAD QUERY THAT GENERATES +AN ERROR”);

+ +

 

+ +

// If the global error array exists at all then +we know there was 1 or more ezSQL errors..

+ +

if ( $EZSQL_ERROR )

+ +

{

+ +

            +// View +the errors

+ +

            +$db->vardump($EZSQL_ERROR);

+ +

}

+ +

else

+ +

{

+ +

            +echo “No Errors”;

+ +

}

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->show_errors

+ +

 

+ +

$db->show_errors – +turn ezSQL error output to browser on

+ +

 

+ +

Description

+ +

 

+ +

$db->show_errors( void )

+ +

 

+ +

$db->show_errors() turns ezSQL error output to the browser on. If you have +not used the function $db->hide_errors this function (show_errors) will have +no effect.

+ +

 

+ +
+ +

 

+ +
+ +

 

+ +

 

+ +

$db->escape

+ +

 

+ +

$db->escape – Format +a string correctly in order to stop accidental mal formed queries under all PHP +conditions.

+ +

 

+ +

Description

+ +

 

+ +

$db->escape( string )

+ +

 

+ +

$db->escape() makes any string safe to use as a +value in a query under all PHP conditions. I.E. if magic quotes are turned on +or off. Note: Should not be used by itself to guard against SQL injection +attacks. The purpose of this function is to stop accidental mal formed queries.

+ +

 

+ +

Example 1

+ +

 

+ +

            +// Escape and assign the value..

+ +

            +$title = +$db->escape(“Justin’s and Amy’s Home Page”);

+ +

 

+ +

            +// Insert in to the DB..

+ +

$db->query(“INSERT INTO pages (title) VALUES (’$title’)”) ;

+ +

 

+ +

Example 2

+ +

 

+ +

            +// Assign the value..

+ +

            +$title = “Justin’s and Amy’s +Home Page”;

+ +

 

+ +

            +// Insert in to the DB and escape at the same time..

+ +

$db->query(“INSERT INTO pages (title) VALUES (’”. $db->escape($title).”’)”) ;

+ +
+ +

 

+ +
+ +

 

+ +

Disk Caching

+ +

 

+ +

ezSQL has the ability +to cache your queries which can make dynamic sites run much faster.

+ +

 

+ +

If you want to cache +EVERYTHING just do..

+ +

 

+ +

            $db->use_disk_cache = true;

+ +

            $db->cache_queries = true;

+ +

            $db->cache_timeout = 24;

+ +

 

+ +

For full details and +more specific options please see:

+ +

 

+ +

·         +mysql/disk_cache_example.php

+ +

·         +oracle8_9/disk_cache_example.php

+ +

 

+ +

 

+ +
+ + + + diff --git a/ez_sql_with_smarty.html b/ez_sql_with_smarty.html new file mode 100644 index 00000000..ddc27384 --- /dev/null +++ b/ez_sql_with_smarty.html @@ -0,0 +1,185 @@ + + + + + + Making Smarty EZier. + + + + Making Smarty EZier.
+

If you have used Smarty for templating your websites then you already know what a great resource it is. If not, you are missing out. Go to Smarty.php.net and check it out.
+
+ In this article I will explain how using Smarty with EzSQL by Justin Vincent (justinvincent.com) can make your life even “ezier”. My intent here is not to explain the in depth workings of Smarty or EzSQL but to show how the use of these two classes together is synergistic.
+
+ First we’ll have quick look at EzSQL, then Smarty, then the two combined.
+
+ EzSQL:
+

+ When getting data from a database using native php it might look something like this:
+
+ + + + + +
mysql_connect("localhost", "mysql_user", "mysql_password")
+ or die("could not connect");
+ mysql_select_db("mydb");
+ $result = mysql_query("SELECT id, name FROM mytable");
+ while ($row = mysql_fetch_array($result))
+ {
  printf ("ID: %s Name: %s", $row[0], $row["name"]);
+ }
+ mysql_free_result($result);
+
+
+ In the reality I think many of us now use a class of some kind so it would look a little more like this (Y.M.M.V.)
+
+ + + + + +
require '/path/to/myConnector.php';
+ + $db=new myConnector("localhost", "mysql_user", "mysql_password");
+
+ + $db->query("SELECT id, name FROM mytable");
+ + while ($db‡next_record()){
+ +   printf ("ID: %s Name: %s", $db->f(‘id’), $db->f(‘name’);
+ + }
+
+
+ I think you’d agree that’s fewer lines and generally a better solution. Using a database class is great as it wraps the database, makes getting the data easier, but doesn’t cover the presentation aspect. That still has to be done by intermingling php and HTML
+
+ EzSQL is only a little different in it’s set up, however the results are returned as an array as you can see here.
+
+ + + + +
define("EZSQL_DB_USER", "mysql_user");
+ define("EZSQL_DB_PASSWORD", "mysql_password");
+ + + define("EZSQL_DB_NAME", "my_db");
+ + + define("EZSQL_DB_HOST", "localhost");
+ + + require ‘/path/to/ez_sql.php';
+
+ + + $result_array = $db->get_results("SELECT id, name FROM mytable");
+ + + foreach($result_array as $row_obj) {
+   printf ("ID: %s Name: %s", $db->id, $db->name;
+ + + }
+
+
+
+ + + Smarty:
+

+ + + Next we’ll take a look at the Smarty process
+
+ + + Smarty is a class. In simplistic terms it's usage is:
+ + + - Instantiate a Smarty object
+ + + - Push the data for the page into the Smarty object
+ + + - Get Smarty to apply the template(s) to the data -- (“skin” the object so to speak)
+
+ + + In code it looks like this:
+
+ + + + +
include '/path/to/Smarty.php';
$Smarty=new Smarty;
$Smarty->assign('somevar', 'some data I want to display');
$Smarty->assign('some_db_results', $db->get_my_data());
$Smarty->display('name_of_template.tpl');
+
+
+ + + The template had entries for {$somevar} and {$some_db_results} so the assigned data is displayed inside the template at those points.
+
+ + + You have probably already figured out the ending to this story but in case you haven’t, this is what happens when you put these two classes together.
+
+ Putting them together:
+
+
This is the code for both the php file and the template file. The synergy being that the results from EzSQL can be passed straight into Smarty and the layout is done there. This means less coding for the programmer and more flexibility for the designer.
+
+ + + + +
define("EZSQL_DB_USER", "mysql_user");
+ define("EZSQL_DB_PASSWORD", "mysql_password");
+ + + define("EZSQL_DB_NAME", "my_db");
+ + + define("EZSQL_DB_HOST", "localhost");
+ require ‘/path/to/ez_sql.php';
+ // the $db object is instantiated by the php file
+
include '/path/to/Smarty.php';
$Smarty=new Smarty;
+
$Smarty->assign('DB_RESULTS', $db->get_results("SELECT id, name FROM mytable");
$Smarty->display('template.tpl');
+
+ //template file template.tpl
+
+ + + <table border="0" cellspacing="0" cellpadding="3">
+ {foreach from=$DB_RESULTS item="row_obj"}
+  <tr>
+   <td>ID: {$row_obj ->id}</td>
+  <td>Name: {$row_obj ->name}</td>
+ </tr>
+{/foreach}
+</table>

+
+
+ + + Of course this is not a real world example. In the real world, at least in my real world, all the configuration is done in a “loader” file that takes care of all the constant definitions, data paths, instantiations and so on. This file is prepended in the httpd container for the domain or in .htaccess file so the process is automated. So, in reality the php file only contains the last two lines of the example.
+
+ Since switching to this method of creating sites my workload has gotten lighter, my code is more readable and the number of line of code is far less. Even the design side is more fun as you can control the display in the presentation layer and not have to worry abobut tweaking the underlying PHP files. All in all faster and “ezier”... Try it.
+
+ Happy coding,
+
+ + Steve Warwick Ph.D.
+ + + articles@clickbuild.com
+
+ + + For information on using my modified version of Justin’s class ez_results with Smarty check out my article “EZ pagination For Smarty.”
+ + + \ No newline at end of file diff --git a/index.html b/index.html index 716c6c01..c6d1a6e0 100644 --- a/index.html +++ b/index.html @@ -20,29 +20,11 @@

PHP class to make interacting with a database ridicu

-Welcome to GitHub Pages.

+ ezSQL Documentation +

-

This automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new gh-pages branch locally. If you’re using GitHub Desktop, simply sync your repository and you’ll see the new branch.

- -

-Designer Templates

- -

We’ve crafted some handsome templates for you to use. Go ahead and click 'Continue to layouts' to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved.

- -

-Creating pages manually

- -

If you prefer to not use the automatic generator, push a branch named gh-pages to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.

- -

-Authors and Contributors

- -

You can @mention a GitHub username to generate a link to their profile. The resulting <a> element will link to the contributor’s GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.

- -

-Support or Contact

- -

Having trouble with Pages? Check out our documentation or contact support and we’ll help you sort it out.

+

help

+

smarty