首页 > web前端 > js教程 > 正文

JSQL SQLProxy 的 php 版本代码_javascript技巧

php中文网
发布: 2016-05-16 18:28:13
原创
1442人浏览过
复制代码 代码如下:

date_default_timezone_set("PRC");
$host = stripslashes($_POST['host']);
if($host == null) { $host = 'localhost'; };
$user = stripslashes($_POST['user']);
if($user == null) { $user = 'root'; };
$password = stripslashes($_POST['password']);
if($password == null) { $password = ''; };
$database = stripslashes($_POST['database']);
if($database == null) { die('DataBase Name Needed!'); };
$SQL = stripslashes($_POST['SQL']);
if($SQL == null) { die('SQL Needed!'); };
$db = mysql_connect($host, $user, $password);
mysql_select_db($database,$db);
if(preg_match('/\s*select/i',$SQL)) {
$result = mysql_query($SQL,$db);
$rowcount = mysql_num_rows($result);
if($rowcountprintf("null");
}
else
{
$fieldsarr = array();
while ($field = mysql_fetch_field($result)) {
$fieldsarr[] = $field;
};
printf("[");
$rowindex = 0;
while ($row = mysql_fetch_row($result)) {
$rowindex++ ;
printf("{");
$fieldcount = count($fieldsarr);
for($i=0;$i$fieldname = $fieldsarr[$i]->name;
$fieldtype = $fieldsarr[$i]->type;
$fieldvalue = $row[$i];
if($fieldvalue==null) {
$fieldvalue = "null";
}
else if($fieldtype=='string'){
$fieldvalue = "'$fieldvalue'";
}
else if($fieldtype=='datetime'){
$fieldvalue = str_replace("-","/",$fieldvalue);
$fieldvalue = "new Date('$fieldvalue')";
}
printf("%s : %s ", $fieldname, $fieldvalue);
//printf($fieldtype);
if($iprintf(" , ");
};
};
printf("}");
if($rowindexprintf(" , ");
};
};
printf("]");
};
mysql_free_result($result);


}
else if(preg_match('/\s*insert/i',$SQL)) {
mysql_query($SQL,$db);
$effectrows = mysql_affected_rows();
if($effectrows==1) {
printf("true");
} else {
printf("false");
};
}
else if(preg_match('/\s*update/i',$SQL)) {
mysql_query($SQL,$db);
$effectrows = mysql_affected_rows();
printf($effectrows);
}
else if(preg_match('/\s*delete/i',$SQL)) {
mysql_query($SQL,$db);
$effectrows = mysql_affected_rows();
printf($effectrows);
}
else if(preg_match('/\s*create\s+table/i',$SQL)) {
if(mysql_query($SQL,$db)) {
printf("true");
} else {
printf("false");
};
}
else if(preg_match('/\s*drop\s+table/i',$SQL)) {
if(mysql_query($SQL,$db)) {
printf("true");
} else {
printf("false");
};
}
else {
printf("command not supported yet!");
};
mysql_close($db);
?>
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号