简体   繁体   English

无法连接到Xampp MySQL以外的数据库

[英]Not able to connect to database other than xampp mysql

I am not sure what is happening with my code, My project is running smoothly under XAMPP Server, i am able to make connection between mysql and php, But when i moved this to another system, which has mysql community server, their the code is not working, i mean database is connecting, but not able to fetch data from the database. 我不确定我的代码正在发生什么,我的项目在XAMPP Server下运行顺利,我能够在mysql和php之间建立连接,但是当我将其移至另一个具有mysql社区服务器的系统时,它们的代码是无法正常工作,我的意思是数据库正在连接,但无法从数据库中获取数据。

Sample Code is as follows: 示例代码如下:

$host='localhost'; // Host name
$username='root'; // Mysql username
$password=''; // Mysql password
$db_name='test'; // Database name
$connect=@mysql_connect($host,$username,$password) or die("Cannot Connect to database");
@mysql_select_db($db_name,$connect) or die ("Cannot find database");

app Code: 应用程式码:

 $sql="SELECT * FROM test.userdet WHERE emailId='$uName' and pwd='$pwd'";
 $result=mysql_query($sql);
 $count=mysql_num_rows($result);

according to $count i am redirecting it to other page. 根据$ count我将其重定向到其他页面。

I able to run it on other systems which has XAMPP itself, but its not running with mysql community server. 我可以在本身具有XAMPP的其他系统上运行它,但不能与mysql社区服务器一起运行。

//Thanks to NullPointer, i got it by PDO, from now onwords i will continue with PDO for transactions. //感谢NullPointer,我是PDO提供的,从现在开始,我将继续使用PDO进行交易。

Now i facing a new problem, i am calling a php_db script via ajax, after executing all PDO statements its not returning to ajax, Code snippet is below: 现在我面临一个新问题,我通过ajax调用php_db脚本,在执行所有PDO语句后,它不返回到ajax,代码段如下:

ajax call:- 阿贾克斯电话:-

  $.ajax({
      type: "POST",
      url: "common/dbPhpScripts/updateEvent.php",
      data: 'json=' + det,
      dataType: 'json',
      cache: false,
      success: function () {
          $('#cal').fullCalendar('refetchEvents');
          $('#edit_event').dialog('close');
      }
  });

sample php code after using PDO: 使用PDO之后的示例php代码:

$stringData = $_POST['json'];
$mynewarray = json_decode($stringData, true);
$title=$mynewarray['title'];
$start= $mynewarray['start'];
$end= $mynewarray['end'];
$createDate=$mynewarray['createDate'];
$insertQuery=$db->exec("INSERT INTO calendar (User_Id, StartDateTime, EndDateTime, Event_Title, Create_Date) VALUES ('07','$start','$end','$title','$createDate')");

where i am going wrong? 我要去哪里错了?

its good to see what you getting in 很高兴看到你进入

success: function (data) {
   alert("data");
}

also you need to echo result in common/dbPhpScripts/updateEvent.php not redirect if you redirect you wont get result in ajax 如果您重定向您也不会在ajax中获得结果,那么您也需要在common/dbPhpScripts/updateEvent.php回显结果

It defiantly should be your credentials. 绝对应该是您的凭据。 Make sure your Username and Password are correct as well as the Database name and the Host. 确保您的用户名和密码以及数据库名称和主机正确无误。 Different server have different credentials. 不同的服务器具有不同的凭据。

EG : EG:

WAMP WAMP

$username='root'; // Mysql username
$password=''; // Mysql password

MAMP MAMP

$username='root'; // Mysql username
$password='root'; // Mysql password

Given remove the @ sign. 给定删除@符号。 Don't suppress warnings using @SuppressWarnings 不要使用@SuppressWarnings禁止显示警告

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM