Example #1
0
 /**
  * @param Connection $db
  * @depends testConnect
  */
 public function testExecute(Connection $db)
 {
     $table = uniqid('table_');
     $db->execute("CREATE TABLE {$table} (id int, display varchar(100));");
     for ($i = 1; $i < 5; $i++) {
         $value = md5($i);
         $db->execute("INSERT INTO {$table} VALUES (:id, :value);", array($i, $value));
     }
     return array($table, $db);
 }
Example #2
0
 public function execute($params = null)
 {
     if (is_null($params)) {
         $params = $this->params;
     }
     $sql = $this->connection->execute($this->sql, $params);
     $data = new Data($this->fetchAllAssoc($sql));
     $meta = $this->parseMeta($this->connection->execute('SHOW META'));
     return new Result($data, $meta, $sql);
 }
function remcat()
{
    global $_REQUEST, $login, $pass, $server, $db, $nb;
    $cat = trim(strip_tags($_REQUEST['cat']));
    $cat = strtr($cat, ' ', '');
    if (strlen($cat) == 0) {
        echo '<p class="error"><strong>Error:</strong> You must provide a category name.</p>';
    } else {
        $con = new Connection($login, $pass, $server, $db);
        $con->execute("DELETE FROM sptbl_spam_categories WHERE category_id='" . $con->escapeStr($cat) . "'");
        $con->execute("DELETE FROM sptbl_spam_references WHERE category_id='" . $con->escapeStr($cat) . "'");
        $con->execute("DELETE FROM sptbl_spam_wordfreqs WHERE category_id='" . $con->escapeStr($cat) . "'");
        $nb->updateProbabilities();
        echo "<p class='success'>The category has been just removed.</p>";
    }
}
function remcat()
{
    global $_REQUEST, $login, $pass, $server, $db, $nb;
    $cat = trim(strip_tags($_REQUEST['cat']));
    $cat = strtr($cat, ' ', '');
    if (strlen($cat) == 0) {
        echo '<p class="erreur"><strong>Erreur:</strong> Vous devez donner un nom de catégorie.</p>';
    } else {
        $con = new Connection($login, $pass, $server, $db);
        $con->execute("DELETE FROM nb_categories WHERE category_id='" . $con->escapeStr($cat) . "'");
        $con->execute("DELETE FROM nb_references WHERE category_id='" . $con->escapeStr($cat) . "'");
        $con->execute("DELETE FROM nb_wordfreqs WHERE category_id='" . $con->escapeStr($cat) . "'");
        $nb->updateProbabilities();
        echo "<p class='succes'>La catégorie vient d'être supprimée.</p>";
    }
}
Example #5
0
 /**
  * Execute the query and return the number of rows affected
  *
  * @return int
  */
 public function execute()
 {
     return $this->connection->execute($this->getQuery());
 }
DISCLAIMED. IN NO EVENT SHALL ADRIAN KOSMACZEWSKI BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// The binary plist and the SOAP formatters require huge amounts of memory!
ini_set('memory_limit', '128M');
require_once 'data/database.php';
require_once 'formatters/formatterfactory.php';
// Get all the data from the database
$limit = $_GET["limit"];
if (!$limit) {
    $limit = "50";
}
// Before calling mysql_real_escape_string() you have to connect to the DB...!
$conn = new Connection();
$conn->open();
$query = "SELECT * FROM data ORDER BY RAND() LIMIT " . mysql_real_escape_string($limit);
$data = $conn->execute($query);
$conn->close();
// Depending the "format" parameter in the query string,
// output the data in different formats
$format = mysql_real_escape_string($_GET["format"]);
$formatter = FormatterFactory::createFormatter($format);
$formatter->setData($data);
header('Content-type: ' . $formatter->getContentType());
$output = $formatter->formatData();
echo $output;
 private function prepareEmptyDatabaseTable()
 {
     $this->connection->execute('CREATE TABLE IF NOT EXISTS test_table (id INTEGER PRIMARY KEY);)');
 }
Example #8
0
    /**
     * Creates tables for testing listTables/describe()
     *
     * @param Connection $connection
     * @return void
     */
    protected function _createTables($connection)
    {
        $this->_needsConnection();
        $schema = new SchemaCollection($connection);
        $result = $schema->listTables();
        if (in_array('schema_articles', $result) && in_array('schema_authors', $result)) {
            return;
        }
        $table = <<<SQL
CREATE TABLE schema_authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(50),
bio TEXT,
created DATETIME
)
SQL;
        $connection->execute($table);
        $table = <<<SQL
CREATE TABLE schema_articles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR(20) DEFAULT 'testing',
body TEXT,
author_id INT(11) NOT NULL,
published BOOLEAN DEFAULT 0,
created DATETIME,
CONSTRAINT "title_idx" UNIQUE ("title", "body")
CONSTRAINT "author_idx" FOREIGN KEY ("author_id") REFERENCES "schema_authors" ("id") ON UPDATE CASCADE ON DELETE RESTRICT
);
SQL;
        $connection->execute($table);
        $connection->execute('CREATE INDEX "created_idx" ON "schema_articles" ("created")');
    }
Example #9
0
 /**
  * @param $sql
  *
  * @return bool|DBResultSet
  */
 private function fireSql($sql)
 {
     $sql .= ';';
     if (!is_null($this->decodeFunction)) {
         $sql = call_user_func($this->decodeFunction, $sql);
     }
     return $this->_conn->execute($sql);
 }
function execute($query)
{
    $conn = new Connection();
    $conn->open();
    $recordset = $conn->execute($query);
    $conn->close();
    return $recordset;
}