 |
ผมรบกวนสอบถามเรืองการเชื่่อมต่อ database มีปัญจากการ connecttion จะแก้อย่าไงหรครับ |
|
 |
|
|
 |
 |
|
Access denied for user 'root'@'localhost' (using password: YES)
User หรือ Pass ผิดครับ เวลาเข้า phpMyAdmin คุณใช้ user, pass อะไรครับ ก็ใส่ตัวนั้นแหละ
|
 |
 |
 |
 |
Date :
2014-05-29 09:09:02 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
$conn = mysql_connect('localhost','root',' 9899')
or die("ไม่สามารถติดต่อ MySql ได้");
mysql_select_db("db_eng")
or die ("ไม่สามารถเลือกใช้งานฐานข้อมูลได้");
mysql_query("SET NAMES tis620");
?>
จากบรรทัดที่ 2 ผมเช็คแล้วครับตรงครับ แต่ผมสงสัยว่า
มีอีกตัวหนึ่งครับ คือ อยู่ใน foder include
class_main.inc
Code (PHP)
<?
error_reporting(1);
class admin_control {
// ======= Start variable of class ===========
/*var $host = "localhost";
var $database = "thawangpha_1";
var $user = "thawangpha_1";
var $password = "9899";*/
var $database = "db_eng";
var $user = "root";
var $password = "9899";
var $link_con = 0;
var $sqlquery;
var $result;
var $count;
var $ERRNO;
var $ERROR;
var $totalpage;
var $startx;
// ======= Stop variable of class ===========
// ======= Start method of class ===========
function admin_control () {
global $HTTP_HOST;
$this->link_con = mysql_connect($this->host,$this->user,$this->password);
mysql_select_db($this->database,$this->link_con);
mysql_db_query($this->database,"SET NAMES tis620");
}
function send_cmd($query){
$this->sqlquery = $query;
$this->result = mysql_query($query,$this->link_con);
$this->ERRNO = mysql_errno();
$this->ERROR = mysql_error();
$this->count = mysql_num_rows($this->result);
return $this->count;
}
function get_id () {
return mysql_insert_id($this->link_con);
}
function get_data(){
return mysql_fetch_row($this->result);
}
function fetch_data(){
return mysql_fetch_array($this->result);
}
function data_seek($torow){
return mysql_data_seek($this->result,$torow);
}
function num_rows(){
return $this->count;
}
function page_count($data_record,$pagesize,$pageid){
$this->totalpage = (int)($data_record / $pagesize);
if(($data_record % $pagesize) != 0){
$this->totalpage += 1;
}
if(isset($pageid)){
$this->startx = $pagesize * ($pageid -1);
}else{
$pageid = 1;
$this->startx = 0;
}
return $this->startx;
}
function show_error() {
echo $this->sqlquery."<br>".mysql_errno().":".mysql_error();
}
function free_result(){
mysql_free_result($this->result);
}
function close() {
mysql_close($this->link_con);
}
function convert_date($date)
{
list ($YYYY, $MM, $DD) = split ('[/.-]', $date);
$date_out="$DD/$MM/$YYYY";
return $date_out;
}
function convert_date_to_db($date)
{
list ($YYYY, $MM, $DD) = split ('[/.-]', $date);
$date_out="$YYYY-$MM-$DD";
return $date_out;
}
// ======= Stop method of class ===========
}
// end of class
$db = new admin_control();
//---------------- Setup Enviralment --------
/*function textreplace($text){
$searchtext ="\"";
$replacetext=""";
return str_replace ($searchtext, $replacetext, $text);
}
function inservalue($text){
$searchtext ="\'";
$replacetext="''";
return str_replace ($searchtext, $replacetext, $text);
}*/
function textreplace($text){
$searchtext ="\"";
$replacetext=""";
return str_replace ($searchtext, $replacetext, $text);
}
function inservalue($text){
$searchtext ="\'";
$replacetext="''";
return str_replace ($searchtext, $replacetext, renHTML($text));
}
function querysql($text){
$searchtext ="\'";
$replacetext="''";
return str_replace ($searchtext, $replacetext, $text);
}
//????????? renHTML() ???????????????????????????????? HTML ???????????????????????????????????
function renHTML($strTemp){
$strTemp = nl2br(htmlspecialchars($strTemp));
return $strTemp;
}
?>
แบบนี้ผมผิดตรงไหนหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2014-05-29 09:20:17 |
By :
myboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณไป Comment var $host = "localhost"; หรือเปล่าครับ?
|
 |
 |
 |
 |
Date :
2014-05-29 09:28:10 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะ connect แบบ oop หรอ
|
 |
 |
 |
 |
Date :
2014-05-29 09:33:07 |
By :
yokvoice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูแล้วเป็น code สีดำ น่ะครับ ผิดใช่ไหมคับแบบนี้ผมเคยเห็นแต่ว่า code จะเป็นตัวสีแดงครับ

ผมทำผิดตรงไหนหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2014-05-29 10:07:55 |
By :
myboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
class db {
var $host;
var $pass;
var $db_name;
var $charset;
function __construct() {
$this->host = 'localhost';
$this->user = 'root';
$this->pass ='root';
$this->db_name = 'db_name';
$this->charset = 'utf-8';
}
function connect() {
$conn = mysql_connect($this->host, $this->user, $this->pass);
if($conn) {
mysql_select_db($this->db_name);
mysql_query('SET NAMES '.$this->charset);
}
return $conn;
}
}
?>
|
 |
 |
 |
 |
Date :
2014-05-29 10:23:20 |
By :
yokvoice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ
ให้เอามาแทนไฟล์นี้ได้เลยใช่ไหมครับ
|
 |
 |
 |
 |
Date :
2014-05-29 13:40:32 |
By :
myboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าแก้จากไฟล์เดิมได้ไหมครับ
|
 |
 |
 |
 |
Date :
2014-05-29 13:48:02 |
By :
myboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปัญหาคือผมแก้ไม่ถูกครับจากไฟล์ตัวอย่างภาพที่เอาให้ดูครับ จะทำอย่างไหรดีครับ connect ไม่ได้เลีครับ
|
 |
 |
 |
 |
Date :
2014-05-29 14:33:04 |
By :
myboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก code ที่ให้ไป สมมุติตั้งชื่อ ไฟล์ db.php
Code (PHP)
<?php
include_once 'db.php';
$db = new db();
$conn = $db->connect();
if($conn)
{
echo 'ติดต่อได้';
}
else
{
echo 'ติดต่อไม่ได้';
}
?>
|
 |
 |
 |
 |
Date :
2014-05-29 14:46:11 |
By :
yokvoice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับผมขอบคุณครับ
|
 |
 |
 |
 |
Date :
2014-05-29 16:01:47 |
By :
myboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|