Welcome to the new Linux Foundation Forum!

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

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<br />
$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

Comments

  • paxpax Posts: 6
    edited April 2015
    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.

    Edit : You Should not use it, replace instead by mysqli :
    <?php
    	//Settings mySQL variable
    
            $db_host = "127.0.0.1";
            $db_name = "dbname";
            $db_username = "myuser";
            $db_password = "mypassword";
    
    	//Connect to mySQL 
    
            $connect = mysqli_connect($db_host, $db_username, $db_password, $db_name);
    
    	//Set, UTF8 output charset 
    
    	mysqli_set_charset($connect, "utf8");
    ?>
    
Sign In or Register to comment.