T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 64
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 93
  Total Coupon : 36
  Other Tutorials :
  Member : 215
  Visitor Online : 2
  Today Visit: 304
  Total Visitor : 301326
  Most Online : 41
::: Sponsored Links :::

PR 4 For This Webpage

Vinaora Logo
Home Today :

My Batch Query

Author : olegpetkov

A batch file is a specific file with series of sql queries.You can copy files of this sort by loading them and clicking on Execute button, or by writing them down in the Query text field and clicking again on button Execute. If last query in your script return the result you can see it in same window.

PHP Example :

<?php
$mydb 
"localhost";
$mydatabase "test";
$myusername "root";
$mypassword "";
$myquery='';
if  (isset(
$_GET['myquery'])) $myquery =stripslashes(stripslashes(addslashes($_GET['myquery'])));
elseif  (isset(
$_POST['myquery'])) $myquery =stripslashes(stripslashes(addslashes($_POST['myquery'])));
if  (isset(
$_GET['Execute'])&&urldecode($_GET['Execute'])=="Execute"$haveresult=batch_query($myquery);
elseif  (isset(
$_POST['myquery'])&&urldecode($_POST['Execute'])=="Execute"$haveresult=batch_query($myquery);

//---------------------------------------------------
function connect_to_db(){
    global 
$mydatabase$mydb$myusername$mypassword;
    
$db mysql_connect($mydb$myusername$mypassword);
    if (!
$db) die("A database selection error has occurred!");
    
mysql_select_db($mydatabase,$db);
    return (
$db);
}
//------------------------------------------------------
function batch_query($dquery){
if (
$dquery=='') {echo 'The query was empty'; exit;}
$queryes explode(';',$dquery);
$db=connect_to_db();

foreach (
$queryes as $query){
$query=trim($query);

if (
$query<>'') {
$result mysql_query($query.';',$db) or die (mysql_error($db));
}
}
return (
$result);
}
//------------------------------------------------------
function show_result($result){
if (
$result && mysql_num_rows($result) > 0) {
echo 
"<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"0\">\n";
echo 
'<tr>';
 while (
$i mysql_num_fields($result)) {
    
$meta mysql_fetch_field($result$i);
   echo 
'<td>';
   echo 
$meta->name;
   echo 
'</td>';
   
$i++;
}
echo 
'</tr>';
while (
$line mysql_fetch_array($resultMYSQL_ASSOC)) {
    echo 
"\t<tr>\n";
    foreach (
$line as $col_value) {
        echo 
"\t\t<td>$col_value</td>\n";
    }
    echo 
"\t</tr>\n";
}
echo 
"</table>\n";
mysql_free_result($result);
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><title>MyQuery php</title></head>
<body bgcolor="#E2E2E2" text="#666666" link="#666666" vlink="#666666" alink="#666666">
<form name="form1" method="POST" action="">
  <table border="0" align="center" cellpadding="8" cellspacing="0">
    <tr> 
      <td align="center" valign="top"><a href="http://www.delphipages.com/result.cfm?SR=oleg%5Fpetkov&AO=and&RequestTimeout=500#root#/index.cfm">
      You can download "MyQuery" free windows application from here!</a></td>
    </tr>
    <tr> 
      <td align="center" valign="top">
      <textarea name="myquery" cols="80" rows="15" id="myquery">
<?php 
//It is only for a test! You can clear php code from here ....
if (!isset($_POST['myquery'])||!(isset($_POST['Clear'])&&$_POST['Clear']=='Clear')) print_r("
DROP TABLE IF EXISTS test.abon_plan;

CREATE TABLE IF NOT EXISTS test.abon_plan
(
id INTEGER NOT NULL auto_increment PRIMARY KEY,
abon_plan varchar(40),
abon_plan_cyr varchar(60),
comment varchar(100),
code char(3) NOT NULL DEFAULT 'IKO',
deleted enum('N','Y') NOT NULL
);

 INSERT INTO test.abon_plan (abon_plan, abon_plan_cyr ,comment ,code)
VALUES ('RESTRICTED.REST', 'RESTRICTED' ,'512' ,'RES');
 INSERT INTO test.abon_plan (abon_plan, abon_plan_cyr ,comment ,code)
VALUES ('MINIMALEN.BIN', 'MINIMAL' ,'256' ,'MIN');
 INSERT INTO test.abon_plan (abon_plan, abon_plan_cyr ,comment ,code)
VALUES ('IKONOMIC.IKO', 'IKONOMIC' ,'512' ,'IKO');
 INSERT INTO test.abon_plan (abon_plan, abon_plan_cyr ,comment ,code)
VALUES ('UNIVERSAL.UNI', 'UNIVERSAL' ,'1024' ,'UNI');
 INSERT INTO test.abon_plan (abon_plan, abon_plan_cyr ,comment ,code)
VALUES ('GOLD.GOLD', 'GOLD' ,'1024' ,'GLD');

SELECT 
id,
abon_plan,
abon_plan_cyr,
comment,
code,
deleted
FROM test.abon_plan ORDER BY abon_plan ASC;</textarea></td>
"
); 
// ... ... ... to here!
?>
</textarea></td>
    <tr> 
      <td height="42" nowrap> <div align="right">
          <input name="Clear" type="submit" id="Clear" value="Clear">
          <input name="Execute" type="submit" id="Execute2" value="Execute">
        </div></td>
    </tr>
    <tr>
      <td height="42"><div align="center">
          <?php if ($haveresultshow_result($haveresult);?>
        </div></td>
    </tr>
  </table>
  </form>
</body>
</html>





Other Example
Count Rows From 2 Tables
mysql syntax error reporting
Count Rows From 2 Tables
Anti SQL Injection Login Filter


::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007