Re: Connecting to mysql from another host

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well you it depends on what method you use to access mysql. If for instance if you use PDO you could do something like that to connect and query:
<?php

 $dbhost = 'remote_hostname';
 $dbuser = 'mysql_username';
 $dbpass = 'mypass';
 $db = 'database_to_use';

$db_handler = new PDO('mysql:host='.$dbhost.';dbname='.$db, $dbuser, $dbpass);

$query = "SELECT id, fname, lname FROM users WHERE id>'1'";
$st_handler  = $db_handler->prepare($query);
$st_handler->execute();

?>

Have in mind that you must have installed the PDO mysql modules using pear for this method to work. There are other methods like this one:
http://www.php-mysql-tutorial.com/connect-to-mysql-using-php.php

Have fun,

Theodoros Goltsios
Kinetix Tele.com Support Center
email: tgol@xxxxxxxxxx, support@xxxxxxxxxx
Tel. & Fax: +30 2310556134
WWW: http://www.kinetix.gr/



joefazee wrote:
I want to connect to a database hosted on another server like from
www.sample.com i want to connect to www.example2.com.what did i need to do?

Thanks.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux