开发者

PHP and MySQL "Database connection"

开发者 https://www.devze.com 2023-03-16 22:34 出处:网络
many time i try to connect PHP forms with MySQL Database but every time 开发者_运维百科i got one message connection is not available.

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

精彩评论

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