|
@@ -138,9 +138,9 @@ class Base
|
|
|
final function selectOne($table)
|
|
|
{
|
|
|
//验证table是否合法
|
|
|
- if (!is_string($table) || !preg_match("/^[a-zA-Z_]+[a-zA-Z0-9_]{0,}$/", $table)) {
|
|
|
+ if (!$this->verifyTable($table)) {
|
|
|
if (gettype($table) == 'string') {
|
|
|
- throw new TableException("表名不能包含怪字符且不能以数字开头");
|
|
|
+ throw new TableException("表名不能包含怪字符且不能以数字开头,获取到的是". $table);
|
|
|
}
|
|
|
throw new TableException("表名必须是字符串加下划线,目标字符为". gettype($table));
|
|
|
}
|
|
@@ -165,6 +165,7 @@ class Base
|
|
|
{
|
|
|
throw new Variable(_i('Invalid %s format', 'data'), __LINE__);
|
|
|
}
|
|
|
+ echo $this->getTable($table);
|
|
|
$this->modelSQL = $sql = "INSERT INTO " . $this->getTable($table) . "(`" . join("`, `", $replaceObj['fields']) . "`) VALUES('" . join("', '", $replaceObj['values']) . "')";
|
|
|
$this->setQuery($sql);
|
|
|
$this->setError();
|
|
@@ -201,7 +202,10 @@ class Base
|
|
|
*/
|
|
|
protected function createInsertReplaceObj($dataArray)
|
|
|
{
|
|
|
- if (sizeof($dataArray) > 0 || get_object_vars($dataArray) > 0) {
|
|
|
+ if(gettype($dataArray) == 'object') {
|
|
|
+ $dataArray = get_object_vars($dataArray);
|
|
|
+ }
|
|
|
+ if (sizeof($dataArray) > 0) {
|
|
|
$keys = array();
|
|
|
$values = array();
|
|
|
foreach ($dataArray AS $key => $value) {
|
|
@@ -852,18 +856,9 @@ class Base
|
|
|
*/
|
|
|
protected function getTableAlias($name)
|
|
|
{
|
|
|
- if (!is_string($name) || (
|
|
|
- // table
|
|
|
- !preg_match("/^[a-zA-Z_]+[a-zA-Z0-9_]{0,}$/", $name) &&
|
|
|
- // `table`
|
|
|
- !preg_match("/^`[a-zA-Z_]+[a-zA-Z0-9_]{0,}`$/", $name)) &&
|
|
|
- // table alias
|
|
|
- !preg_match("/^[a-zA-Z_]+[a-zA-Z0-9_]{0,}\s+[a-zA-Z]+[a-zA-Z0-9_]{0,}$/", $name) &&
|
|
|
- // `table` alias
|
|
|
- !preg_match("/^`[a-zA-Z_]+[a-zA-Z0-9_]{0,}`\s+[a-zA-Z]+[a-zA-Z0-9_]{0,}$/", $name)
|
|
|
- ) {
|
|
|
+ if (!$this->verifyTable($name)) {
|
|
|
if (gettype($name) == 'string') {
|
|
|
- throw new TableException("表名不能包含怪字符且不能以数字开头");
|
|
|
+ throw new TableException("表名不能包含怪字符且不能以数字开头,获取到的是". $name);
|
|
|
}
|
|
|
throw new TableException("表名必须是字符串加下划线,目标字符为". gettype($name));
|
|
|
}
|
|
@@ -1211,6 +1206,31 @@ class Base
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 验证数据表名是否符合规范
|
|
|
+ * 表名不能以数字开头,
|
|
|
+ *
|
|
|
+ * @param string $name
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ final public function verifyTable($name) {
|
|
|
+ if (!is_string($name) || (
|
|
|
+ // table
|
|
|
+ !preg_match("/^[a-zA-Z_]+[a-zA-Z0-9_]{0,}$/", $name) &&
|
|
|
+ // `table`
|
|
|
+ !preg_match("/^`[a-zA-Z_]+[a-zA-Z0-9_]{0,}`$/", $name)) &&
|
|
|
+ // table alias
|
|
|
+ !preg_match("/^[a-zA-Z_]+[a-zA-Z0-9_]{0,}\s+[a-zA-Z]+[a-zA-Z0-9_]{0,}$/", $name) &&
|
|
|
+ // `table` alias
|
|
|
+ !preg_match("/^`[a-zA-Z_]+[a-zA-Z0-9_]{0,}`\s+[a-zA-Z]+[a-zA-Z0-9_]{0,}$/", $name) &&
|
|
|
+ // database.table
|
|
|
+ !preg_match("/^[a-zA-Z]+\.[a-zA-Z]+[a-zA-Z0-9_]{0,}$/", $name) &&
|
|
|
+ !preg_match("/^[a-zA-Z]+\.[a-zA-Z]+[a-zA-Z0-9_]{0,}\s+[a-zA-Z]+[a-zA-Z0-9_]{0,}$/", $name)
|
|
|
+ ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
/**
|
|
|
* 如果不存在指定的方法则调用提示错误
|
|
|
*
|