简体   繁体   English

PHP 和 MySQL “数据库连接”

[英]PHP and MySQL “Database connection”

many time i try to connect PHP forms with MySQL Database but every time i got one message connection is not available.很多次我尝试将 PHP forms 与 MySQL 数据库连接,但每次我得到一个消息连接都不可用。

so my question is that if some one have a knowledge of good tutorial websites then please tell me as i can learn from their所以我的问题是,如果有人了解好的教程网站,那么请告诉我,因为我可以从他们那里学习

You have to do something like this:你必须做这样的事情:

$user="username";
$password="password";
$con=mysql_connect('10.10.10.10',$user,$password);
$db_selected = mysql_select_db("database_name", $con) or die("DB connecting problem");

<?php
$user="uname";
$pwd="pwd";

$con = mysql_connect("localhost",$user,$pwd);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

// Create database
if (mysql_query("CREATE DATABASE my_db",$con))
 {
 echo "Database created";
 }
else
 {
  echo "Error creating database: " . mysql_error();
 }


 $selectdb = mysql_select_db("my_db", $con);
  if (!$selectdb)
  {
     die('Database Not selected.');
  }

 mysql_close($con);
?>

Katty, you could head to the official PHP function reference page for MySQL which is: Katty,您可以访问 MySQL 的官方 PHP function 参考页面:

http://php.net/manual/en/ref.mysql.php http://php.net/manual/en/ref.mysql.php

initially focus on mysql_connect().最初专注于 mysql_connect()。 There's also some community submitted content, which could come handy for testing.还有一些社区提交的内容,可以方便地进行测试。

Also if you could provide the code u are using and error thrown, that would help.此外,如果您可以提供您正在使用的代码并抛出错误,那将有所帮助。

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

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