Jump to content

How do I make a Mysql Database Connection

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Chan

Chan

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 204 posts
I'm not sure that I am doing this correctly so can someone post some code how they connect to a MySQL database?

I've got

MySQL_Connect();

$query = "Select * FROM test";

MySql_Query($query);


but nothing returns.

#2
Void

Void

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 411 posts
You have the mysql_connect() empty. It should have more values. You should also select your database.


$username = "myUser";

$password = "myPassword";

$server = "localhost";


// Connect to MySQL

mysql_connect($server,$username,$password) 

     or die ("Unable to connect to MySQL server.");


// Select the Database

$db = mysql_select_db("myDB") 

     or die ("Unable to select database");


// Run your query

$query = "SELECT * FROM test";

$results = mysql_query($query);


// Get your results

$myrow = mysql_fetch_row($results); // You can also use a while loop for multiple results



Void