Jump to content


Photo

Adding tables to a Database...


  • Please log in to reply
15 replies to this topic

#1 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 31 March 2003 - 03:08 AM

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.

#2 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 31 March 2003 - 07:03 AM

It is pretty easy actually, as long as the user name and password has the permission to connect to the mysql server remotly.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#3 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 31 March 2003 - 08:01 AM

uh please post an example how? :)

#4 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 31 March 2003 - 12:56 PM

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?
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#5 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 31 March 2003 - 06:15 PM

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

#6 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 31 March 2003 - 06:33 PM

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!!
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#7 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 31 March 2003 - 06:39 PM

[quote=\"shivabharat\"][quote]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);
[/quote]

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?

#8 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 31 March 2003 - 06:54 PM

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

#9 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 31 March 2003 - 11:03 PM

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?

#10 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 31 March 2003 - 11:45 PM

$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";

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#11 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 31 March 2003 - 11:47 PM

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);

?>


#12 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 01 April 2003 - 12:08 AM

$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 .
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#13 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 01 April 2003 - 12:28 AM

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

#14 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 02 April 2003 - 04:47 AM

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

#15 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 02 April 2003 - 06:53 AM

lol, so your site that you are working on is actually located on the box in Arkansas.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#16 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 03 April 2003 - 01:26 AM

yes




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users