Exemple #1
0
//echo "<br>";
//Insert or update to DB
PDO_Execute("INSERT INTO users (name, age) VALUES (:name, :age)", array("name" => "apple", "age" => 150));
PDO_Execute("UPDATE users SET age = 200 WHERE name = 'apple'");
//Last Insert ID
//$id = PDO_LastInsertId();
//print_r($id);
?>


<?php 
echo "<br> Using variables in statements ";
$name = "omt";
$tablename = "users";
$selectVar = "age";
$newAge = PDO_FetchOne("SELECT {$selectVar} FROM {$tablename} WHERE name = :name", array("name" => $name));
//Select one column from the row with some specific details know.
print_r("newAge " . $age);
echo "<br>";
?>


<html >
<head> 
<script src="jquery-1.10.2.min.js"></script>
<script >
$(document).ready(function(){
    $('.button').click(function(){
        var clickBtnValue = $(this).val();
        var ajaxurl = 'ajax.php',
        data =  {'action': clickBtnValue};
Exemple #2
0
function table_pk($table)
{
    // @pk
    $table_columns = table_columns($table);
    if (!$table_columns) {
        return null;
    }
    $pk = "";
    global $global_columns;
    foreach ($global_columns[$table] as $column) {
        if ($column["pk"]) {
            if ($pk) {
                $pk .= ":" . $column["name"];
            } else {
                $pk = $column["name"];
            }
        }
    }
    if ($pk) {
        // Possible returns: "col1", "col1:col2", "col1:col2:col3"
        return $pk;
    }
    global $db_driver;
    if ("sqlite" == $db_driver) {
        // Detect PK for:
        // UNIQUE (nagroda, id_gracza)
        // When there are multiple pks there is no info about it in PRAGMA table_info.pk,
        // we need to get it from the SQL string that was used to create the table.
        $sql = PDO_FetchOne("SELECT sql FROM sqlite_master WHERE type = 'view' OR type='table' AND name = :name ", array(":name" => $table));
        if (preg_match("#UNIQUE\\s*\\(\\s*(\"?\\w+\"?(\\s*,\\s*\"?\\w+\"?)*)\\s*\\)#i", $sql, $match)) {
            $cols = $match[1];
            $cols = str_replace("\"", "", $cols);
            $cols = preg_replace("#\\s+#", "", $cols);
            $cols = str_replace(",", ":", $cols);
            return $cols;
            // "nagroda:id_gracza"
        }
    }
    foreach ($table_columns as $col => $type) {
        return $col;
    }
}
Exemple #3
0
    }
    //print "<table border=1>";
    //print "<tr><td>Id</td></tr>";
    //$result = $dbh->query('SELECT * FROM IDs');
    $result = PDO_FetchAll('SELECT * FROM IDs order by Id');
    $option = '';
    //print count($result)." - ".print_r($result);
    foreach ($result as $row) {
        $temp = "<option value='" . $row['Id'] . "'>" . $row['Id'] . "</option>";
        $option = $option . $temp;
    }
    //print "</table>";
}
//End SQLLite Section
$exists = "SELECT count(*) FROM IDs ";
$count = PDO_FetchOne($exists);
if ($count > 20) {
    $count = 20;
}
$foot = "";
if ($count > 0) {
    $foot = " <form action='SectionI.php' method='post'>";
    $foot = $foot . "Next Section<input type='submit' value='Go'></form>\t";
    $totals = "<form action='SectionI.php' method='post'><input type='hidden' value='X' name = 'hSectionNo'>Output file<input type = 'submit' value='submit'></form>";
    //$foot = $foot.$totals;
}
$dbh = null;
?>
			<select size=<?echo $count; ?> width="300">
			<?php 
echo $option;
Exemple #4
0
         //echo "post".$_POST[$id]."<br>";
         //**************Are we trying to push data? if so, let's do it!
         if ($_POST['id'] != '') {
             $sql = "Delete from " . $QName . " Where Id = " . $id;
             PDO_Execute($sql);
             $sql = "INSERT INTO " . $QName . " (" . $QNameCols . ") Values (" . $id . $values . ")";
             //echo $sql;
             PDO_Execute($sql);
             $sql = "Select Min(id) from Ids where id > " . $id;
             //echo $sql;
             $id = PDO_FetchOne($sql);
             //print "post_Insert: ".$id;
             if ($id == '') {
                 $sql = "Select Min(id) from Ids";
                 //echo $sql;
                 $id = PDO_FetchOne($sql);
             }
             //print $sql;
         }
         //******* End of push data attempt
     }
     //($formError>0)
 }
 //$idlist =
 $result = PDO_FetchAll("SELECT * FROM Ids");
 foreach ($result as $row) {
     if ($id == $row['Id']) {
         $idlist = $idlist . "<option value='" . $row['Id'] . "' selected>" . $row['Id'] . "</option>";
     } else {
         $idlist = $idlist . "<option value='" . $row['Id'] . "'>" . $row['Id'] . "</option>";
     }