2014-09-23 28 views
0

嗨,我有問題連接到我的數據庫`警告:mysql_query():拒絕用戶'peace4love'@'localhost'(使用密碼:否)/ home// home/peace4love/public_html中無法建立指向服務器的鏈接,請在/ home/peace4love/public_html中建立一個指向服務器的鏈接,然後在/ home/peace4love/public_html /ivegotdiamonds.com/wp-content/plugins/hsquare/config-new.php線14 錯誤,查詢failed`這裏是代碼:無法建立到服務器的鏈接Mysql

<?php 
require_once(ABSPATH."/lib/myplug.php"); 
$objMem = new myPlug(); 

$table_name = "h_config"; 
[email protected]$_POST["addme"]; 
global $wpdb; 

$act=$_REQUEST["act"]; 
if($act=="upd") 
{ 
    $recid=$_REQUEST["id"]; 
    $sSQL="select * from ".$table_name." where config_id=$recid"; 
    $result = mysql_query($sSQL) or die ('Error, query failed'); 
    if (mysql_num_rows($result) > 0) 
    { 
     if($row = mysql_fetch_assoc($result)) 
     { 
      $id = $row['config_id']; 
      $c_key = $row['c_key']; 
      $c_value = $row['c_value']; 
      $c_index = $row['c_index']; 
      $c_record = $row['c_record']; 
      $c_record_2 = $row['c_record_2']; 
      $c_record_3 = $row['c_record_3']; 
      $c_record_4 = $row['c_record_4']; 
      $btn  = "Update Record"; 
      $hidval = 32; 
     } 
    } 
} 
else 
{ 
    $btn ="Add New Record"; 
    $c_key = ""; 
    $c_value = ""; 
    $c_index = ""; 
    $c_record = ""; 
    $c_record_2 = ""; 
    $c_record_3 = ""; 
    $c_record_4 = ""; 
    $btn = "Add New Record"; 
    $hidval = 31; 
} 

>

+0

如果我需要猜測,我會說你沒有配置用戶訪問數據庫的用戶peace4love從本地主機。 – Miki 2014-09-23 20:55:42

+0

我在代碼中的任何地方缺少一個'mysql_connect',是否在別處調用? – favoretti 2014-09-23 20:58:38

+0

這是一個不同網站的數據庫。 – user2986348 2014-09-23 20:59:10

回答

0

警告

MySQL的API(所有mysql_ *函數)一起使用,將從PHP被移除。您應該考慮切換到mysqliPDOhttp://php.net/manual/en/mysqlinfo.api.choosing.php

回答

你需要調用mysql_query()之前調用mysql_connect()連接到你的數據庫服務器。它用你提供給它的參數打開一個到你的MySQL服務器的連接:主機,端口,用戶名,密碼。

您還需要選擇使用mysql_select_db()函數的db。從PHP文檔

例如,試圖在端口3306(MySQL默認端口)與mysql_user登錄和mysql_password密碼連接到數據庫foo服務器localhost上:

<?php 

$link = mysql_connect('localhost:3306', 'mysql_user', 'mysql_password'); 
if (!$link) { 
    die('Not connected : ' . mysql_error()); 
} 

$db_selected = mysql_select_db('foo', $link); 
if (!$db_selected) { 
    die ('Can\'t use foo : ' . mysql_error()); 
} 

?> 

然後,您可以使用mysql_query()函數。