开发者

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.

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:

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

initially focus on 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜