PHP Function問題

我的主頁面 Index.php
<?php require_once('connSQL.php'); ?>

connSQL.php的內容如下:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connSQL = "localhost";
$database_connSQL = "資料庫";
$username_connSQL = "帳號";
$password_connSQL = "密碼";
$connSQL = mysql_pconnect($hostname_connSQL, $username_connSQL, $password_connSQL) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query('SET NAMES "UTF8"');

if (!function_exists("Article")) {
	function Article($id){

		//重點問題所在 Start
		$hostname_connSQL = "localhost";
		$database_connSQL = "資料庫";
		$username_connSQL = "帳號";
		$password_connSQL = "密碼";
		$connSQL = mysql_pconnect($hostname_connSQL, $username_connSQL, $password_connSQL) or trigger_error(mysql_error(),E_USER_ERROR);
		mysql_query('SET NAMES "UTF8"');
		//重點問題所在 End

		$colname_Recordset1 = $id;
		if (isset($_GET['art_id'])) {
		  $colname_Recordset1 = $_GET['art_id'];
		}
		mysql_select_db($database_connSQL, $connSQL);
		$query_Recordset1 = sprintf("SELECT art_content FROM article WHERE art_id = %s", GetSQLValueString($colname_Recordset1, "int"));
		$Recordset1 = mysql_query($query_Recordset1, $connSQL) or die(mysql_error());
		$row_Recordset1 = mysql_fetch_assoc($Recordset1);
		$totalRows_Recordset1 = mysql_num_rows($Recordset1);
		return $row_Recordset1['art_content'];
	}
}
if (!function_exists("GetSQLValueString")) {
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""){
		if (PHP_VERSION < 6) {
			$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
		}
	$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
		switch ($theType) {
			case "text":
			$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;    
			case "long":
			case "int":
			$theValue = ($theValue != "") ? intval($theValue) : "NULL";
			break;
			case "double":
			$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
			break;
			case "date":
			$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;
			case "defined":
			$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
			break;
		}
	return $theValue;
	}
}
?>

問題當我在 Index呼叫 Article() 方法的時候
如果不加入 問題重點部分的話 Article()是沒辦法執行的...

但是按照我的邏輯來說XD
Index一開始就已經require 整個connSQL.php 應該就包含把
整個連結資料庫的語法了。

為什麼我在呼叫 Article方法的時候 他卻不知道
$connSQL 的內容是甚麼

想請交高手解答一下。
表達能力不是很好,如果有哪邊不清楚,可隨時補充

評論

Sign In or Register to comment.