- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:reference:connection:qstr

# qStr

##### See Also

addQ()

##### Syntax

    string qStr(
           string $unquoted,
           optional bool $dontFixQuotes=false
           )

### Description

The function `qStr()` takes an input string, and allows it to be:

1. Wrapped in single quotes.The value can then be used, for example in an SQL statement.
2. Have quotes inside the string escaped in a way that is appropriate for the database. This is done wherever possible using PHP driver functions e.g. MySQL real_escape_string. The second parameter, `$dontFixQuotes` stops any internal quoting happening, This parameter was mostly used in older versions of PHP when the now removed `magic_quotes` parameter was enabled, and the 2 methods were in conflict.

### Usage

    $string = "Patrick O'Reilly";

    $SQL = "SELECT * FROM names WHERE name='$string'";

    $result = $db->Execute($SQL);

    /*
     * Execution fails  due to mismatched ` characters
    */

    $qString = $db->qStr($string);

    /*
     * function returns 'Patrick O\'Reilly' (The resulting string is database-specific)
    */

    $SQL = "SELECT * FROM names WHERE name=$qString";

    $result = $db->Execute($SQL);

    /*
     * Execution Succeeds
     */

v5/reference/connection/qstr.txt · Last modified: 2016/01/16 15:28 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top