Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Update to include PDO #801

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions examples/php-example.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
<?
<?php

#
# Example PHP server-side script for generating
# responses suitable for use with jquery-tokeninput
#

# Connect to the database
mysql_pconnect("host", "username", "password") or die("Could not connect");
mysql_select_db("database") or die("Could not select database");

try{
$dbh = new PDO('mysql:host=host;dbname=database,user,password');
}
catch(PDOException $e){
echo $e->getMessage();
}
# Perform the query
$query = sprintf("SELECT id, name from mytable WHERE name LIKE '%%%s%%' ORDER BY popularity DESC LIMIT 10", mysql_real_escape_string($_GET["q"]));
$query = sprintf("SELECT id, name from mytable WHERE name LIKE '%%%s%%' ORDER BY popularity DESC LIMIT 10",
mysql_real_escape_string($_GET["q"]));

$stmt = $dbh->prepare("SELECT id, name from mytable WHERE name LIKE ? ORDER BY popularity DESC LIMIT 10");
$stmt->bindValue(1,'%%%'.htmlspecialchars($_GET["q"]).'%%%');
$stmt->execute();
$arr = array();
$rs = mysql_query($query);

# Collect the results
while($obj = mysql_fetch_object($rs)) {
while($obj = $stmt->stmt->fetch(PDO::FETCH_OBJ)) {
$arr[] = $obj;
}

Expand Down