4 Replies - 1074 Views - Last Post: 20 August 2010 - 07:40 PM Rate Topic: -----

#1 Mazaagy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-July 09

CONNECT PHP WITH MYSQL..?

Posted 18 August 2010 - 04:42 AM

Hi,

I am a biginner of database website..

I have the experiance of connection php with email id..

Anyhow, I don't know how to connect with database.

Can anyone explain , that -

What are the easy steps to connect php file with mysql web server..?

thanks

This post has been edited by Mazaagy: 18 August 2010 - 04:43 AM

Is This A Good Question/Topic? 0
  • +

Replies To: CONNECT PHP WITH MYSQL..?

#2 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: CONNECT PHP WITH MYSQL..?

Posted 18 August 2010 - 04:49 AM

Use the mysql_connect method to connect with a mysql database

mysql_connect("location of  server", "username", "password");



Read this for more info
Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,028
  • Joined: 08-June 10

Re: CONNECT PHP WITH MYSQL..?

Posted 18 August 2010 - 04:50 AM

connecting itself is pretty simple.

example code (PDO is PHP’s database abstraction layer)
# define your DB
$dsn = "mysql:host=localhost;dbname=" . $your_database_name_here ;
# connect
$pdo = new PDO($dsn, $your_user_name, $your_user_password);
# set error handling
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);



after that you can use the prepare() or query() methods to query your DB.
$stmt = $pdo->query($your_sanitized_sql_query);

foreach ($stmt as $row)
{
	# do something with the result array
}


Was This Post Helpful? 1
  • +
  • -

#4 Mazaagy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-July 09

Re: CONNECT PHP WITH MYSQL..?

Posted 19 August 2010 - 03:16 PM

Thanks a lot crunch, dormilich for took intrest with my question - I will try & contact back you, if anything else..

This post has been edited by Mazaagy: 19 August 2010 - 03:20 PM

Was This Post Helpful? 0
  • +
  • -

#5 Dorito_125  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 88
  • Joined: 13-December 08

Re: CONNECT PHP WITH MYSQL..?

Posted 20 August 2010 - 07:40 PM

You should use mysqli when supported the i stands for improved, and improved is always better! :bananaman:

I do the following to connect to my database.


$dbc = mysqli_connect('www.amazingdatabases.biz', 'username', 'password', 'database_name') or die('Error connecting to Database');
$query = "SELECT * FROM your_table"; // Remember, mysql queries don't require a semi colon when submitted through php.
$result = mysqli_query($dbc, $query);

while( $row = mysql_fetch_array($result))
{
    echo $row['row_in_my_database'];
}

mysqli_close($dbc); // Never forget to close your connection!


This post has been edited by Dorito_125: 20 August 2010 - 07:42 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1