Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connecting to phpMyAdmin database with PHP/MySQL

I've made a database using phpMyAdmin , now I want to make a register form for my site where peaple can register .I know how to work with input tags in HTML and I know how to insert data into a database but my problem is that I don't know how I can connect to the database that is already made in phpMyAdmin.

like image 634
The Worst Shady Avatar asked Mar 29 '10 05:03

The Worst Shady


People also ask

How do I access phpMyAdmin in MySQL?

To connect to a MySQL database, please follow these steps:Open a browser window and go to www.HostMySite.com. Click on Control Panel Login. Click on MySQL Databases. Select the database from the list and clickphpMyAdmin.

How do you connect MySQL database with PHP?

Connection to MySQL using MySQLi PHP provides mysql_connect() function to open a database connection. This function takes a single parameter, which is a connection returned by the mysql_connect() function. You can disconnect from the MySQL database anytime using another PHP function mysql_close().

Can I use phpMyAdmin with MySQL?

phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL over the Web. phpMyAdmin supports a wide range of operations on MySQL and MariaDB.

Can we connect to any database from PHP?

PHP Data Objects (PDO) is an extension that serves as an interface for connecting to databases. Unlike MySQLi, it can perform any database functions and is not limited to MySQL. It allows flexibility among databases and is more general than MySQL. PDO supports both server and client-side prepared statements.


2 Answers

The database is a MySQL database, not a phpMyAdmin database. phpMyAdmin is only PHP code that connects to the DB.

mysql_connect('localhost', 'username', 'password') or die (mysql_error());
mysql_select_database('db_name') or die (mysql_error());

// now you are connected
like image 97
Amy B Avatar answered Sep 22 '22 01:09

Amy B


Connect to MySQL

<?php

/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'username';

/*** mysql password ***/
$password = 'password';

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
    /*** echo a message saying we have connected ***/
    echo 'Connected to database';
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
?>

Also mysqli_connect() function to open a new connection to the MySQL server.

<?php
// Create connection
$con=mysqli_connect(host,username,password,dbname); 

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?> 
like image 43
railsbox Avatar answered Sep 21 '22 01:09

railsbox