简体   繁体   中英

How do I connect to the DB?

Ok I creating an application that needs to query records from my remote database. I am logged into phpmyadmin and I need to connect to this from my new PHP application. I have the cpanel access and the phpmyadmin tab. Is there something i can do to get the info needed to do this

$connection = mysql_connect(DB_HOST,DB_USER,DB_PASS,true);
mysql_select_db(DATABASE, $connection);

In the Databases section of cpanel, click on the icon labeled "MySQL Databases". There you can create databases and users.

The hostname was probably provided in your welcome email, along with your FTP access. Anyway, it should appear at the top of your phpMyAdmin page, under the label "Server:"

First of all:

Your remote database needs to be accessible by tcp/ip.

Second:

<?php

    //connect to db
    mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db (DB_NAME);

    $strSQL = "SELECT col1,col2 FROM "  . DB_NAME . "." . "tbl1";

    $obj = mysql_query ($strSQL, $objMySQL_Read);  
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM