Using PHP to make mySQL database/tables
Moderator: General Moderators
-
austin0369
- Forum Newbie
- Posts: 19
- Joined: Tue Aug 20, 2002 5:56 pm
Using PHP to make mySQL database/tables
Hey,
Ive been looking threw posts, and all the posts bascially have how to create a table under a database. But i want to make a database with the username as "iwillchange" and a password "soon". The database would be Client, and the table would be Users, then the stuff under that would be Username (primary) password, and email. I know I have to start by connecting to my server, but what do i do after that? Thanks
-Austin
Ive been looking threw posts, and all the posts bascially have how to create a table under a database. But i want to make a database with the username as "iwillchange" and a password "soon". The database would be Client, and the table would be Users, then the stuff under that would be Username (primary) password, and email. I know I have to start by connecting to my server, but what do i do after that? Thanks
-Austin
some info
The http://www.mysql.com site is a great place for all sorts of info.
Try http://www.mysql.com/doc/en/Database_use.html for info on how to create a db, set permissions, and creating tables.
phpScott
Try http://www.mysql.com/doc/en/Database_use.html for info on how to create a db, set permissions, and creating tables.
phpScott
-
austin0369
- Forum Newbie
- Posts: 19
- Joined: Tue Aug 20, 2002 5:56 pm
Ok i came up witht his..but it doesnt work
Code: Select all
<?php
$link = mysql_connect(localhost, USERNAME, PASSWORD) or die(mysql_error());
$sql = "CREATE DATABASE thistest
CREATE TABLE thistestis
username VARCHAR (40) NOT NULL,
password VARCHAR (40) NOT NULL,
PRIMARY KEY (username))";
// Run the query
mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
?>Privileges
If you are running this on a remote server the username and password might not have the right Privileges to create databases and tables and the like.
insert how you make your db connection a the top of this script then run it. It should return what permmsions you have kinda like,
phpScott
Code: Select all
<?php
$sql="SHOW GRANTS FOR link@localhost";
$result = mysql_query($sql);
if (!$result)
{
$msg = 'Error 411 - ' . mysql_error();
echo $msg;
return false;
}
while($row = mysql_fetch_row($result))
{
echo $rowї0]."<br>";
}
?>It will let you know if you can create db's table's and the like.GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'link'@'localhost' IDENTIFIED BY PASSWORD '3dd401ac51a8df42'
phpScott
-
austin0369
- Forum Newbie
- Posts: 19
- Joined: Tue Aug 20, 2002 5:56 pm
Sorry, i have no idea what u8 mean by what u posted..either way it doesnt seem to work for me..this is what i have:
Code: Select all
<?php
$connection = mysql_connect(localhost, FTPusername, FTPpassword) or die(mysql_error());
$sql="SELECT * FROM localhost";
$result = mysql_query($sql, $connection);
if (!$result)
{
$msg = 'Error 411 - ' . mysql_error();
echo $msg;
return false;
}
while($row = mysql_fetch_row($result))
{
echo $rowї0]."<br>";
}
?>try this.
remeber to put in your username and password for the db that you are currently using.
change link to your username. This will show you what you are allowed to do, such as select, update, delete, grant, and so on.
remeber to put in your username and password for the db that you are currently using.
Code: Select all
<?php
$connection = mysql_connect(localhost, FTPusername, FTPpassword) or die(mysql_error());
$sql="SHOW GRANTS FOR link@localhost";
$result = mysql_query($sql);
if (!$result)
{
$msg = 'Error 411 - ' . mysql_error();
echo $msg;
return false;
}
while($row = mysql_fetch_row($result))
{
echo $rowї0]."<br>";
}
?>-
austin0369
- Forum Newbie
- Posts: 19
- Joined: Tue Aug 20, 2002 5:56 pm
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
a little explanation
you can use almost all mySql commands, including create database, create table, and the like in php and executing the query like you normally do for update, inserts, and selects.
There is one little problem thought, you have to have permission, or privilage in MySql case, to do those commands.
If you run the script I posted then you will see what you are allowed to do. If it isn't listed then you can not perform that action. It is as simple as that, either you are allowed to or not.
I have on my local development machine don't exactly what you are trying to do, but I gave myself permission to do so.
However when I tried to do a create table on my host, it came up with an error to the effect that the user didn't have permission to do so.
It is a safety feature so that If you want you could create two different users accessing the same db with one allowed to enter and delete info, where another one can only do selects, to view it.
Hope this clarifies things a little for you. By the sounds of it you will have to contact your host to see what you can or can't do.
phpScott
There is one little problem thought, you have to have permission, or privilage in MySql case, to do those commands.
If you run the script I posted then you will see what you are allowed to do. If it isn't listed then you can not perform that action. It is as simple as that, either you are allowed to or not.
I have on my local development machine don't exactly what you are trying to do, but I gave myself permission to do so.
However when I tried to do a create table on my host, it came up with an error to the effect that the user didn't have permission to do so.
It is a safety feature so that If you want you could create two different users accessing the same db with one allowed to enter and delete info, where another one can only do selects, to view it.
Hope this clarifies things a little for you. By the sounds of it you will have to contact your host to see what you can or can't do.
phpScott