Can MySQL tables be created using only PHP?
I don't know much about programming, so I hired someone to create a simple MySQL database with an online form that I can enter information into.
I already setup the MySQL database at my hosting account and gave the programmer the login details as well as an FTP account.
He says he needs my hosting username开发者_运维知识库/password in order to create the database because he needs to use PHPMyadmin to create the tables and test the database.
This seems kinda shady to me. Can't the programmer create the tables using PHP commands alone? I don't want to give out my main username/password to a stranger.
I'm hosted at 1and1.com if that matters any
If you give the MySQL user sufficient database permissions, they can use the CREATE TABLE statement to create the tables without having to use PHPMyadmin. If they don't know how to create tables without using the GUI, then I would be suspicious of their overall database programming abilities as being the lead on your project.
PHP can execute any SQL statement on a MySQL server which it has a valid connection too, including the CREATE TABLE command, however, these will be subject to the "privileges" of the user that PHP used to gain the MySQL connection.
The MySQL user that you provided the login credentials for may not have create table privileges. In this case, PHP could do nothing, as the SQL commands executed would fail.
That said, I don't know why your hosting username/password would be needed to use PHPMyAdmin. Usually a login to PHPMyAdmin is done with the MySQL user, not the hosting user. Though, that user would be subject to the same privilege restrictions, so we're back at part 1:
Does the MySQL user you created for the programmer have create table privileges?
If yes, they should be able to create tables from PHP alone, and if you have PHPMyAdmin installed, they should be able to log in using that same user already (and not your hosting user!)
If no (probably unlikely, though I don't know 1and1), then you will need to provide a MySQL user that does have create table privileges before they can do anything; then see above.
It's possible to submit the necessary CREATE TABLE
queries via php to the database, but the developer is likely more familiar with the way PHPMyAdmin displays what is set up on the server.
Sounds viable to me. Technically he can do everything with PHP alone, but it is much much easier to use PHPMyAdmin.
I think you should hire someone you can trust and give them the tools to help them do a good job.
You don't have to give him your user/pass. You can create a new user in PHPMyAdmin, with less privileges. When he finishes installing your database, just delete that user.
Yes, he can create databases using only PHP, but it is slower than just use PHPMyAdmin.
Probably the person you hired is not very skilled in software development and the only way he know for modifying MySQL is using that web interface.
You can do it this way:
http://www.w3schools.com/php/php_mysql_create.asp
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create database
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
// Create table
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
?>
I might also create a DBUser that has access to the database and tell him to download a mySQL client (such as HediSQL) to do his database work. Then after they are done, just remove the DBUser (or take away all permissions).
精彩评论