Linux.com

Home Linux Community Forums Linux System Administration Web Management How to run php to connect to mysql on debian web server

How to run php to connect to mysql on debian web server

Link to this post 18 Nov 13

I having trouble writing the right script to connect my website to a SQL database they are both on the same server I was just wondering if there any suggestion that I could get on the script that I'm trying to run. I took out the password on purpose
<?php
$db_host = "10.0.0.22";
$db_username = "root";
$db_pass = "blank";
$db_name = "test";

@mysql_connect ("$db_host","$db_username","$db_pass") or die ("could not mysql");
@mysql_select_db("$db_name") or die ("no database");

echo"Sussecful Connection";

?>
the problem that I am running into is that I don't get anything telling me if it connected or not

Link to this post 01 Dec

Hi there,

Try this :


<?php
$db_host = "10.0.0.22";
$db_username = "root";
$db_pass = "blank";
$db_name = "test";

$connect = mysql_connect ($db_host,$db_username,$db_pass);
mysql_select_db($db_name, $connect);

//Here you put your SQL query

?>

You was wrong on the mysql_select_db, also a variable do not need double quote for be processed inside a php fonction.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board