  | 
              
	              
	                
  
    
	 
        เชื่อมฐานข้อมูลได้ แต่เป็นจอขาว ไม่แสดง error ใน localhost จำลองแสดงได้ปกติ แต่พออัพขึ้น host จริงกลายเป็นหน้าขาว     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ตามหัวข้อเลยค่ะ 
 
นี่เป็นตัวอย่าง myconnection.php ที่อยู่คือ hostจริง/Connections/myconnection.php 
Code (PHP) 
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_myconnection = "localhost";
$database_myconnection = "strategy";
$username_myconnection = "root";
$password_myconnection = "strategyyy001";
$myconnection = mysql_pconnect($hostname_myconnection, $username_myconnection, $password_myconnection) or trigger_error(mysql_error(),E_USER_ERROR);
$charset ="SET NAMES 'utf8'";mysql_query($charset) 
or die('Invalid query: ' . mysql_error());
?>
 
 
 
 
นี่เป็นหน้าที่ว่างป่าว คือ index.php จะขอเอามาแค่ส่วนหัวโค้ด php นะคะ ที่อยู่คือ hostจริง/admin/index.php (myconnetion.php กับ index.php อยู่คนละโฟลเดอร์ ไม่รู้ว่าเกี่ยวมั้ยแต่ใน localhost จำลอง แสดงได้ปกติค่ะ) 
Code (PHP) 
<?php require_once('../Connections/myconnection.php'); ?>
<?php include("upload.php"); ?>
<?php
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;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['uname'])) {
  $loginUsername=$_POST['uname'];
  $password=$_POST['pword'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "for_admin.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_myconnection, $myconnection);
  
  $LoginRS__query=sprintf("SELECT username, password FROM `admin` WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $myconnection) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      
    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
 
 
 
 
 
เป็นมือใหม่เพิ่งเคยอัพขึ้นใช้จริงครั้งแรก ขอความกรุณาอย่าต่อว่าเลยนะค่ะ ขอบคุณล่วงหน้าค่ะ ปล.ไม่มีไฟล์ .htaccess
 
 
  Tag : PHP, MySQL, HTML, CSS, HTML5, JavaScript               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2018-10-12 03:03:15 | 
                      By :
                          ampere27 | 
                      View :
                          4359 | 
                      Reply :
                          19 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 # FileName="Connection_php_mysql.htm" 
# Type="MYSQL" 
# HTTP="true" 
 
ข้างบนให้ใส่ ; เซมิโคล่อน ต่อท้ายทุกบันทัด 
บางเวอร์ก็ได้ บางเวอร์ก็ไม่ได้ 
 
หรือ ใส่  /* */ ครอบให้ชัดเจน 
 
ปล. ทำไมไม่ใช้ mysqli ยังใช้ของเก่าอยู่อีก host ใหม่ๆ เขาไม่ใช้แล้ว                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2018-10-12 06:50:17              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 06:48:06 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (PHP) 
<?php
# FileName="Connection_php_mysql.htm";
# Type="MYSQL";
# HTTP="true";
$hostname_myconnection = "localhost";
$database_myconnection = "strategy";
$username_myconnection = "root";
$password_myconnection = "strategyyy001";
$myconnection = mysql_pconnect($hostname_myconnection, $username_myconnection, $password_myconnection) or trigger_error(mysql_error(),E_USER_ERROR);
$charset ="SET NAMES 'utf8'";mysql_query($charset) 
or die('Invalid query: ' . mysql_error());
?>
 
 
 
Code (PHP) 
<?php
/*# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"*/
$hostname_myconnection = "localhost";
$database_myconnection = "strategy";
$username_myconnection = "root";
$password_myconnection = "strategyyy001";
$myconnection = mysql_pconnect($hostname_myconnection, $username_myconnection, $password_myconnection) or trigger_error(mysql_error(),E_USER_ERROR);
$charset ="SET NAMES 'utf8'";mysql_query($charset) 
or die('Invalid query: ' . mysql_error());
?>
 
 
ทำทั้ง2แบบแล้วค่ะยังขาวเหมือนเดิมเลยค่ะ ไม่รู้ว่าเอาไปใส่ถูกมั้ย รบกวนอีกทีนะคะ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 10:28:53 | 
                        By :
                            ampere27 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 รันไฟล์ connect ตรงๆว่าขึ้นข้อความอะไรบ้าง 
http://www.abc.com/Connections/myconnection.php                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 10:45:34 | 
                        By :
                            mee079 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 $myconnection = mysql_pconnect($hostname_myconnection, $username_myconnection, $password_myconnection) or trigger_error(mysql_error(),E_USER_ERROR); 
 
คำสั่งตระกูลนี้ โฮสใหม่ๆ เขาเลิกใช้กันแล้วครับ มันใช้กับ php version เก่าๆ 
 
เปลี่ยนไปใช้ mysqli ครับ 
Code (PHP) 
$myconnection = new mysqli($hostname_myconnection, $username_myconnection, $password_myconnection , $databasename);
if( $myconnection->errno) { die( $myconnection->error); }
$rs = $myconnection->query( $sql_string) or die( $myconnection->error);
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 12:18:15 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ตอนนี้กลับมาเป็นหน้าขาวอีกแล้วค่ะ สลับกันอยู่สองหน้านี้แหละ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 16:15:15 | 
                        By :
                            ampere27 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (PHP) 
$myconnection = new mysqli('yourhost', 'youruser', 'yourpassword' , 'yourdbname');
if( $myconnection->errno) { die( $myconnection->error); }
echo "ok";
 
 
ทดสอบโค๊ดแค่นี้ดูก่อนว่า มันใช้งานได้ 
 
ถ้ามันใช้ได้ ก็เขียน function ขึ้นมาทดแทน คำสั่งเก่า 
 
 
Code (PHP) 
$myconnection = new mysqli('yourhost', 'youruser', 'yourpassword' , 'yourdbname');
if( $myconnection->errno) { die( $myconnection->error); }
function mysql_query($sql, $con){
 return $con->query($sql) or die($con->error);
}
function mysql_fetch_assoc($result){
    return $result->fetch_assoc();
}
 
 
ก็ดูเอาว่าเราใช้คำสั่ง ไหนบ้าง ก็เขียนเลียนแบบไว้ ที่ไฟล์ myconnection.php 
ก็พอจะ ใช้งานได้ เพราะว่าจะไปนั่งแก้ทั้งหมด ก็คงจะเยอะ แต่ 
แต่ถ้าไม่เยอะ ไป find หา เอาแล้วไปแก้ตรงๆ เลยดีกว่า                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 16:30:35 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ตอนนี้ ขึ้นว่า ok อย่างเดียวแล้วค่ะ เดี๋ยวลองวิธีต่อไปค่ะ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 17:23:16 | 
                        By :
                            ampere27 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 หลัง echo"ok"; มีคำสั่งอื่น อยู่ด้วยใช่ไหม เพราะผมให้ลองแค่ 3 บันทัด  
แต่ถ้ามีอยู่ด้วย ก็แสดงว่า mysqli ใช้ได้ 
จะแก้ คำสั่ง หรือจะ เขียน เลียนแบบ ก็ว่ากันไปครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 17:24:51 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ขอเริ่มต้นใหม่เลยนะครับ 
 
ไฟล์ index.php 
 
Code (PHP) 
<?php
$db = new mysqli('xxx', 'xxx', 'xxx' , 'xxx');
if( $db->errno) { die( $db->error); }
function mysql_query($sql, $con){
 return $con->query($sql) or die($con->error);
}
function mysql_fetch_assoc($result){
    return $result->fetch_assoc();
}
function mysql_num_rows($result){
    return $result->num_rows;
}
/////////////////////////////////////////////////
echo "past step 1 connection<br>";
$sql = 'select 123 as a';
$rs = mysql_query($sql, $db);
echo mysql_num_row($rs);
exit; // จบการทดสอบ
//  ข้างล่างนี้เป็นข้อมูลของเดิม ไม่ต้องลบออก
include (.........);
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 17:45:29 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ของทราบ สภาพแวดล้อมของ server หน่อยครับ 
 
เป็น window หรือ linux  
เรียกใช้งานด้วย ip หรือ domain 
 
ใช้โปรแกรมช่วยสร้างเวป หรือ ใช้เครื่องมือ ของ server                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 18:49:08 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 พอดีเป็นข้อมูลของทางสำนักงานรัฐ 
 
จะบอกเท่าที่ทราบนะค่ะ เพราะเขาให้ข้อมูลมาแค่ servername / user / pass / dbname / hostname  ค่ะ 
 
windows หรือ linux ไม่ทราบค่ะ 
 
เรียกใช้งานด้วย ip หรือ domain ลักษณะ แบบนี้ค่ะ xxxxx.xxx.go.th 
 
ใช้ dreamweaver cs6 ช่วยเขียนโค้ด php และเชื่อมต่อ localhost:8080 (ของโปรแกรม USBWebserver ค่ะ) เพื่อจำลองเว็บไปพรีเซ้น แล้วค่อยอัพขึ้น server จริง เลยเจอปัญหาค่ะ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 19:12:30 | 
                        By :
                            ampere27 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 คือถ้าเรียกด้วย index.php ซึ่งเป็นไฟล์ เริ่มต้นระบบ และด้วย โปรแกรมพื้นฐาน แล้วยังขึ้น 500 แสดงว่า ระบบมีปัญหา  
 
ติดต่อ admin เลยครับ 
 
ทดสอบอีกที 
 
<?php phpinfo(); 
 
ถ้ายัง error 500 ก็ชัวร์ว่า ติดต่อ admin เลยครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 19:50:14 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ไม่เข้าใจคำว่า host เดียวกัน ลอง ยกตัวอย่างวิธีเรียก โปรแกรม wordpress กับ program php ที่ทำหน่อยครับ 
เพราะทั้งสองอย่าง คือ php เหมือนกัน 
 
การอ้างอิง อาจจะ conflict กันได้                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-12 20:18:03 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   ตอบความคิดเห็นที่ : 12 เขียนโดย : Chaidhanan เมื่อวันที่ 2018-10-12 17:45:29 
รายละเอียดของการตอบ ::
  ผมลองตามโค้ดของคุณ Chaidhanan
 Code (PHP)
<?php
$db = new mysqli('localhost', 'user', 'pass' , 'test_generic-tests');
if( $db->errno) { die( $db->error); }
function mysql_query($sql, $con){
 return $con->query($sql) or die($con->error);
}
function mysql_fetch_assoc($result){
    return $result->fetch_assoc();
}
function mysql_num_rows($result){
    return $result->num_rows;
}
/////////////////////////////////////////////////
echo "past step 1 connection<br>";
$sql = 'select 123 as a';
$rs = mysql_query($sql, $db);
echo mysql_num_row($rs);
exit; // จบการทดสอบ
ทดลองโดยสภาพแวดล้อมแบบ development เปิดแสดง error, warning, notice ทุกอย่าง มันขึ้นว่า
   Quote:Fatal error: Cannot redeclare mysql_query() 
 
ของผมใช้ PHP 5.5 (ใช้รุ่นนี้เพื่อเป็นขั้นต่ำในการทำของฟรีแจก)
 
ดังนั้นผมว่าที่ของน้องเขาหน้า error หรือหน้าขาวก็คงติดตรงนี้เหมือนกัน คือเหมือนกับว่าไปเจอฟังก์ชั่นสงวนที่ PHP เขาสงวนเอาไว้แม้จะเลิกใช้แล้วก็ตาม เพื่อที่จะแสดง error ว่าฟังก์ชั่นนี้เลิกใช้แล้ว. 
ดังนั้นการสร้างฟังก์ชั่นมาแทนผมคิดว่าใช้ชื่ออื่นน่าจะดีกว่า.
 
ตัวอย่างโค้ดข้างล่างนี้ทำงานได้ครับ ผมใส่ตัว v ท้ายชื่อฟังก์ชั่นเพื่อไม่ให้มันชื่อซ้ำจน re-declare error.
 Code (PHP)
<?php
$db = new mysqli('localhost', 'user', 'pass' , 'test_generic-tests');
if( $db->errno) { die( $db->error); }
function mysql_queryv($sql, $con){
	$result = $con->query($sql);
	if ($result === false) {
		die($con->error);
	}
	return $result;
}
function mysql_fetch_assocv($result){
    return $result->fetch_assoc();
}
function mysql_num_rowsv($result){
    return $result->num_rows;
}
/////////////////////////////////////////////////
echo "past step 1 connection<br>";
$sql = 'select 123 as a';
$rs = mysql_queryv($sql, $db);
echo mysql_num_rowsv($rs);
exit; // จบการทดสอบ
มีต้องแก้หน่อยตรงใน mysql_queryv ไม่สามารถใช้ or die ได้ เนื่องจาก query() method มันจะคืนค่า false เฉพาะเมื่อผิดพลาด นอกนั้นจะคืนค่าเป็น object หรือ true. อ้างอิง  http://php.net/manual/en/mysqli.query.php ผมเลยต้องเอามาใส่ $result แล้วใช้ if เช็คเอา เขียนยาวหน่อย.
  
 
อยากให้จขกท.ลองโค้ดที่สองที่ผมแก้แล้วดู โดยเอาไปปรับค่าต่างๆเช่นพวก host, username, password, db รวมถึงคำสั่ง query ให้ถูกต้องแล้วลองดูอีกที.                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-10-13 12:51:07 | 
                        By :
                            mr.v | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |