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);
?>
精彩评论