Jump to content

Archived

This topic is now archived and is closed to further replies.

Random

Adding tables to a Database...

Recommended Posts

Is there a way to add a table to a database when I do not host the mysql databases? Like through a PHP script? Thanks in advance.

Share this post


Link to post
Share on other sites

It is pretty easy actually, as long as the user name and password has the permission to connect to the mysql server remotly.

Share this post


Link to post
Share on other sites

your connection in the script will be normal except your would obviously us the ip or domain name of the remote machine instead of localhost.

 

 

now on the remote machine every user has an attribute as to where they are allowed to connect from, localhost is the most common, but that isn\'t gonna work for someone from a remote machine even if they know the correct u/n and pass. What sort of admin software do you use on the mysql machine, phpmyAdmin?

Share this post


Link to post
Share on other sites

I have no idea, my friend hosts my site he lives in Arkansas, I live in Indiana.

Share this post


Link to post
Share on other sites
Is there a way to add a table to a database when I do not host the mysql databases? Like through a PHP script? Thanks in advance.

 

Now there are 2 ways of doing that

write a .sql file which would carry the table insert command

 

run the script to create the database.

 

now if u want to do from a program

 

its pretty simple to what u do

 

type in the query

 

$db = mysql_connect("localhost", "admin","admin");



mysql_select_db("db_name",$db);



$sql = "CREATE TABLE test (

 id int(11) NOT NULL auto_increment)";



$result = mysql_query($sql);

 

Hope this helps!!

Share this post


Link to post
Share on other sites
Is there a way to add a table to a database
$db = mysql_connect("localhost", "admin","admin");



mysql_select_db("db_name",$db);



$sql = "CREATE TABLE test (

 id int(11) NOT NULL auto_increment)";



$result = mysql_query($sql);

 

Will this work from a PHP script that I upload and execute in the server, if I just change localhost to the IP/Domain name of the server?

Share this post


Link to post
Share on other sites

yes, that will work as long as your host has given your account permission to remotely modify the database.

Share this post


Link to post
Share on other sites

will it display anything, like \"Database Table Successfully Installed\" or something of that sort? And what if i goto that site over and over, it will only make one table, right?

Share this post


Link to post
Share on other sites
$db = mysql_connect("localhost", "admin","admin"); 



mysql_select_db("db_name",$db); 

   

$sql = "CREATE TABLE test ( 

 id int(11) NOT NULL auto_increment)"; 



$result = mysql_query($sql) or die("Table not created");



echo "Table created sucessfully";

Share this post


Link to post
Share on other sites

im getting this error when I put in the script and changed it around to fit my needs:

 

Warning: mysql_connect() [function.mysql-connect]: Can\'t connect to MySQL server on \'random.travisbsd.no-ip.org\' (60) in /usr/home/random/pubhtml/database.php on line 2

 

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /usr/home/random/pubhtml/database.php on line 4

 

 

here is the script:

 

<?php

$db = mysql_connect("random.travisbsd.no-ip.org", "CENSORED","CENSORED"); 



mysql_select_db("random",$db); 

   

$sql = "CREATE TABLE test ( 

 id int(11) NOT NULL auto_increment)"; 



$result = mysql_query($sql);

?>

Share this post


Link to post
Share on other sites

$db = mysql_connect(\"random.travisbsd.no-ip.org\", \"CENSORED\",\"CENSORED\");

 

Are u sure this is the host name \"random.travisbsd.no-ip.org\"

 

u can also try giving the IP .

Share this post


Link to post
Share on other sites

He said that the port may not be right..is that a possibility?

Share this post


Link to post
Share on other sites

update:

 

he told me to use localhost, and it worked to the point of no errors coming up, so I used a or die statement, and it went off. What could it be now? Localhost is right, and my names, etc. is all right. Thanks

Share this post


Link to post
Share on other sites

lol, so your site that you are working on is actually located on the box in Arkansas.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.