I want to know how to connect to a MySql database in a remote server from windows 7 .I want to give an external connection from Administrative panel.How to give connection to the database ? I have a php coding to insert and retrieve values from the remote database .But before that i need to connect to the remote database manually ? Pls can you help me out with this .#
<?PHP
$user_name = "fbapp";
$password = " 123";
$database = "fb_db";
$server = "mysql.dfw1.stabletransit.com";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "INSERT INTO Sample(Firstname, Lastnamme)
VALUES (35,67)");
$result = mysql_query($SQL);
mysql_close($db_handle);
echo "Records added to the database";
}
else {
echo "Database NOT Found ";
mysql_close($db_handle);
}
?>
Simply create a mysql user and allow the same from your host to connect. So create user at
example1.com MYSQL and allow your new user to connect from your example2.com.
Then allow a firewall rule on mysql port from that very host
open command prompt
mysql -u user_name -ppassword -h ip-adress
use ip-adress of machine where mysql is running
Related
I have a database hosted on my computer using MySQL Workbench. I have a website hosted on my computer using IIS. I have created a database fennypvp and a table accounts with columns id, username and password. I have added multiple entries into the table from MySQL Workbench. Now I am simply trying to get these entries from the website with PHP. For now I'd simply like to be able to print the entries and from there I will work on validating credentials etc. I have look up quite a bit and nothing has worked for me. Here is what I've got so far:
<?php
$host="127.0.0.1";
$port=3306;
$socket="";
$user="root";
$password="";
$dbname="fennypvp";
$con = new mysqli($host, $user, $password, $dbname, $port, $socket)
or die ('Could not connect to the database server' . mysqli_connect_error());
$query = "select * from accounts";
if ($stmt = $con->prepare($query)) {
$stmt->execute();
$stmt->bind_result($field1, $field2);
while ($stmt->fetch()) {
printf("%s, %s\n", $field1, $field2);
}
$stmt->close();
}
$con->close();
?>
The above is code generated by MySQL Workbench although the page sql.php is blank. Any ideas?
Here is the database and table information:
I have a problem connecting to sql database:
<?php
$servername = "localhost";
$username = "";
$password = "";
$myDB = "udemy";
// Create connection
$link = mysqli_connect($servername, $username, $password, $myDB );
if (mysqli_connect_error()){
die ("There was an error connecting to the database");
}
$query = "SELECT * FROM users";
if (mysqli_query($link, $query)){
echo "Query was successfull"
}
?>
Error is showing when I try to connect database named "udemy"...
Set username and password or add a new user in your mysql server and try with those user details.
To create new user :-
To create user in MySQL/MariaDB 5.7.6 and higher, use CREATE USER syntax:
CREATE USER 'new_user'#'localhost' IDENTIFIED BY 'new_password';
then to grant all access to the database (e.g. my_db), use GRANT Syntax, e.g.
GRANT ALL ON my_db.* TO 'new_user'#'localhost';
Where ALL (priv_type) can be replaced with specific privilege such as
SELECT, INSERT, UPDATE, ALTER etc
Then to reload newly assigned permissions run:
FLUSH PRIVILEGES;
Now set newly created username and password in your code.
Hope it helped.
I want to create a table in a MySQL Database with PHP. This is my try:
$dbhost = 'rdbms.strato.de';
$dbusername = 'Userxxx';
$dbuserpass = 'Passwordxxx';
$dbname = 'DBxxx';
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
echo "success in database connection.";
if (!mysql_select_db($dbname)) die(mysql_error());
echo "success in database selection.";
$result = "CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))";
if (mysql_query($result)){
echo "TABLE created.";
}
else {
echo "Error in CREATE TABLE.";
}
But this give me the error
success in database connection.Access denied for user XXX to database XXX
I search a lot but find no successfull solution. Have anyone an idea?
Try connecting without involving PHP:
mysql -u Userxxx -h rdbms.strato.de -pPasswordxxx
If this doesn't work, and I suspect it won't, contact your database administrator to reset your password.
If the password isn't the problem, the remote machine may not be ready to accept your connection. See Access remote database from command line for more on this.
If you can get in, then try to access the database you want:
USE DBxxx;
SHOW TABLES;
Thing is, PHP isn't your problem here; it's the connection. So that's what to investigate.
...and when you get that established, you might look into updating your code; mysql_connect and mysql_select_db are deprecated.
I need some clarification about your hostname,username,password,database name.How ever following code will works in my local server.If you have any doubt about my code please share your host name,password,dbname,etc.
$dbhost = 'localhost';
$dbusername = 'root';
$dbuserpass = '';
$dbname = 'test';
$link_id = mysqli_connect ($dbhost, $dbusername, $dbuserpass,$dbname);
echo "success in database connection.";
$result = "CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))";
if (mysqli_query($link_id,$result)){
echo "TABLE created.";
}
else {
echo "Error in CREATE TABLE.";
}
This is my core PHP code which is used in Magento.
$model_moodle = mysql_connect("localhost","root","123456")
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("moodle",$model_moodle)
or die("Could not select moodle");
//execute the SQL query and return records
$result = mysql_query("SELECT id FROM mdl_course where shortname ='".$data."'");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
$course_id = $row['id'];//display the results
}
//echo "Cource id is=".$course_id;
//close the connection
mysql_close($model_moodle);
I need to Use this code but Using the Magento External Database Connection.
I am using the "Moodle" database in Magento . but I need the code for Magento way.
Use this mysql command to connect to external database :
mysql -h clouddb.com -u root -p dbname;
It asks password for root, then enter password , Then you may login to your external DB!!
Hey guys im trying to connect to an oracle database with php. I tried it like i do it with mysql.
How to do it like this:
$host="localhost";
$user="username";
$pass="password";
$db="database";
$link = mysql_connect($host, $user, $pass) or die ("Keine Verbindung zu der Datenbank moeglich.");
mysql_select_db($db, $link);
$sql = "SQL query goes here";
$result = mysql_query($sql);
How can i do exact this with an oracle database. I have the following connection details
sid, ip, port, username, password.
Simple script:
$DB = '//1.2.3.4:1521/XE';
$DB_USER = 'user';
$DB_PASS = 'pass';
$DB_CHAR = 'AL32UTF8';
$conn = oci_connect($DB_USER, $DB_PASS, $DB, $DB_CHAR);
$statement = oci_parse($conn, 'select 1 from dual');
oci_execute($statement);
$row = oci_fetch_array($statement, OCI_ASSOC+OCI_RETURN_NULLS);
To connect with an Oracle database, you don't use the mysql extension (since that is for MySQL). You should use PDO, with the OCI/Oracle adapter.
You'll want to use PDO to connect to Oracle here is the PHP manual page on creating a connection using PDO, the example given is for MySQL but it will work fine with Oracle. You will need to ensure the PDO:Oracle extension is installed and running on your PHP configuration.