JSP executes SQL statement code

Source: Internet
Author: User

JSP executes SQL statement code
function ExecuteSQL ($operation, $sql)

{

Global $db;

if ($operation = = ' file ')

{

Require_once phpcms_root. ' include/upload.class.php ';

$savepath = ' data/bakup/';

$upload = new Upload (' UploadFile ', $savepath, ', ' sql ', ' 4096000 ', 1);

if (! $upload->up ())

{

ShowMessage ($upload->error ());

}

$sql = file_get_contents ($upload->uploadedfiles[0][saveto]);

Dir_delete ($savepath. Date (' Y '));

if (Trim ($sql)!= ') Sql_execute ($sql);

}

if (empty ($sql))

{

return false;

}

SQL execution

$sql = Stripslashes ($sql);

$sql = Str_replace ("\", "", $sql);

$sql = Str_replace ("R", "", $sql);

$query _items = Split ("; [ T]{0,}n ", $sql);

foreach ($query _items as $key => $value)

{

if (empty ($value))

{

unset ($query _items[$key]);

}

}

if (count ($query _items) > 1)

{

foreach ($query _items as $key => $value)

{

if (! $result = $db->query ($value, ' silent '))

{

return false;

}

}

return true; Exit function

}

Else

{

if (Preg_match ("/^: update| delete| truncate| alter| drop| flush| Insert| replace| Set| CREATE) \s+/i ", $sql))

{

$result = $db->query ($sql);

return $result;

}

Else

{

$result = $db->query ($sql);

$data =array ();

while ($r = $db->fetch_array ($result))

{

$data []= $r;

}

return $data;

}

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.