Connecting to MySQl romote host..... Help!
Posted: Thu Mar 06, 2003 10:12 am
I have been working on my first php and MySQL database site, I seem to have it all up and running without problems on my laptop computer (running OSX Jaguar), now I want to go live with it all I have found I don't really understand how i connect to the remote host datbase to creat a user for the web pages and build the tables which I can do without problems on my "localhost" laptop. I have read some articals on the web and in a couple of books I have at home but they all refer to localhost and show a user connecting from mysql> but how does this relate to working on the remote host rather than the laptop? I wrote a script in php "included below" then placed it on my server and called the page from a browser to try and create the tables thinking this might be a solution but it seems not, I seem to be able to make the connection to the datbase but the script does not run the querys to create the tables. I am getting very confused, if anyone knows where I can get clear information on connecting to the MySQL database to create tables and another user then I would appricate it if they could point me in that dirrection. I have searched the web but I still can't seem to find a clear way of doing this.
Code: Select all
<?php
$hostName = "localhost";
$databaseName = "db_name";
$username = "db_user";
$password = "db_password";
@$connection=mysql_pconnect($hostName,$username,$password);
if (@!$connection) {
echo "Could not connect to the databaseName database using<br />Username: $username and Password: $password at $hostName<br />";
exit;
}else{
echo"Connected<br /><br />";
}
$error = false;
// Create a web user
$query = "grant select, insert, delete, update
on property_list.*
to webuser1 identified by 'propertysite2003'";
if(!mysql_query($query,$connection)) {
echo "<b>* Web user not created</b><br /><br />";
$error = true;
}else{
echo "<b>Web user created</b><br /><br />";
}
// Create the tables
$query = "CREATE TABLE counter (
cpdays text NOT NULL,
month tinyint(2) NOT NULL default '0',
year mediumint(4) NOT NULL default '0',
mtotal int(11) NOT NULL default '0')";
if(!mysql_query($query,$connection)) {
echo "<b>* counter Table not created</b><br /><br />";
$error = true;
}else{
echo "<b>counter</b> table created<br /><br />";
}
// Rest of tables here
?>