My database name is student, my problem is every time I include the database name in php file, using include('student.php'); the student.php file connect the mysql query statement.This is normal, but I want to hide the database name any where or other person doesn't see the database and the database settings.
I'm not sure if this is the correct answer, but how we usually do this in Rails is by setting the database settings as environment variables on the server (and locally) and have our app use these environment variables to configure that database connection. You could do the same thing in your PHP app to hide the db name (and password) from people editing the code and from source control. It also helps for deploying to multiple servers.
The best solution you can do is set up your database with a mirror with a user which only has permission to do normal stuff, but not access or drop databases.
That way it doesn't matter what your students do or see the database as.
Related
I have a PHP application which is on a production server and it`s meant to register users to some services. It has two forms which registers a user in a different table from my database.
Problem is that today one of the tables disappeared and I was able to restore it from a backup. But this dose`t get rid of the problem.
How do I investigate this in order to determine how that table got lost and most likely dropped by some bot or something.
How would you proceed in a situation like this?
There are two ways:
Have a working backup of the system, and restore the files from it.
An undelete tool might help, if you deleted the db very recently (and ideally, if you unplugged the computer right afterward).
As for doing it with MySQL, though...on all systems i'm aware of, no. MySQL tables are files in the server's data directory, and dropping a table deletes those files. Once they're gone, they're gone, and only the methods above can get them back. A database is a directory of those files, and dropping it deletes the whole directory.
Check this free software
http://www.majorgeeks.com/Restoration_d4474.html
More information here - http://emaillenin.blogspot.com/2010/11/recover-accidentally-deleted-mysql.html
If your tables got dropped, find out what mysql users have privileges to drop a table (there shouldn't be many) and what services log in with that user credentials.
Maybe you have a web form with a php backend that doesn't clean up (escape) input, so you were maybe open to sql injection.
In that case, you could check you webserver access log.
I'm helping a friend migrate her wordpress server to GoDaddy, and I think I may have bitten off more than I can chew... I've never migrated a wordpress before. This page here is the Wordpress wiki for moving Wordpress when your domain isn't changing. It doesn't seem to complex, but I'm terrified of accidentally ruining this website and I don't understand a couple of things on the wiki.
The Wiki says
If database and URL remains the same, you can move by just copying your files and database.
Does this mean that I can just log in to her server from Filezilla and copy all of the files on the server? What does database mean, is that something separate from the files on the server?
If database name or user changes, edit wp-config.php to have the correct values.
This sort of goes with my first question.. What initiates a database name or user change?
Apologies for my ignorance, but after an hour or so of searching around for these answers I'm left just as confused.
Last but not least, is there anything else I should be aware of when migrating a wordpress? I'm a little nervous..
You are going to need to migrate you instalation in two parts.
Part 1 you already eluded to. You will need to copy the files from one server to another. I am guessing you know how to do this so I will not dive any deeper into it. If you do need more explanation, please let me know and I will edit the question.
Part 2 is what you mentioned but said you did not understand. Copying the database of wp install. Wordpress runs off of PHP and MySQL. The "files" part in part 1 is the PHP files (along with some html and css). You need to log into his MySQL server and do an export of his database. You should be able to export the database (How to export mysql database to another computer?) and import it into his new server on GoDaddy. (Error importing SQL dump into MySQL: Unknown database / Can't create database).
Just take things slow, follow the guides that I have linked and do not delete anything from the first server until everything is working on the second. Please let me know if you do not understand anything.
if you don't feel confortable with database exports and imports, try using plugins like:
http://wordpress.org/plugins/duplicator/
or
http://wordpress.org/plugins/wordpress-move/
Check his docs for info.
Luck!
• A database is literally a data base. It's where websites (and other applications) store their data eg. For Wordpress, it would be data such as posts, user information etc.
If you are using a cPanel setup then you would need to get access to it and navigate to phpMyAdmin which is the GUI for managing a database.
Now I'm not sure what type of setup you're using but that should be a start.
• A database has a connection server address (usually localhost), a database name, username and password. These are setup at the time of setting up a database.
When migrating servers, you would need to update those details in the wp-config.php file (I think around line 19 or so).
• The annoying part about migrating Wordpress to another server is the domain change as you have to update the old domain with the new domain throughout the database. However since you're not changing domain names, it should be a smooth ride as long as the new server supports PHP and has a database.
I have a bunch of php pages that run on local host. Its basically a web dashboard for different web apps. I have a config.php file that has all my variables in it. They are mainly urls, password and usernames.. Now I want to remove the config file and replace it with a database. I don't want to set up an entire database though. Is there a way maybe with mysql lite that I can create a datebase file that acts like a database? So if I ever copy all the php files and move them to another computer I can just copy the database file and it will work right away. Is this possible? If yes please explain in detail how I would create, connect, and retrieve variables.
Regards
You want to use SQLite. Check some tutorials and do it how they suggest:
http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html
http://zetcode.com/databases/sqlitetutorial/
http://freshmeat.net/articles/sqlite-tutorial
SQLite will do what you want: http://php.net/manual/en/book.sqlite.php.
The databases are self-contained within a single file. Check their website for more information: http://www.sqlite.org/
SQLite (nothing to do with MySql Lite Administrator) is an SQL database which stores all its data in easily transferable files.
PHP has an extension that supports SQLite.
I've been working on a website on my own xampp server on my computer with my own database and everything and so far it's been pretty smooth, surprisingly. Now I want to upload it to a host, and I found a free web host and I was able to upload the site through dreamweaver/ftp. I exported my DB into an SQL query and than ran that query on the live DB so that they would have the same data.
I'm curious, what's the best way to keep these DB's in sync?
1) In my header.php, I specify some connection variables for my local db and I have to make sure to change them when I upload header.php to the site so they have the correct connection variables for the remote db. Maybe if I had a file on my hosting server and a file on my local server that specified the connection information and just never messed with them?
2) If I change something in my local DB, I have to copy the SQL and run it in my remote one as well. Is there a good way to handle this?
Thanks again!
http://www.databasejournal.com/features/mysql/article.php/3355201/Database-Replication-in-MySQL.htm
For #1, you can either do that--the route most people take--or make the config file check the IP before loading server specific configuration. If the IP is 127.0.0.1, you load your development configuration. If it is the IP of the host, it loads a different config.
I personally do not know of a better way to handle #2. So, this answer will have to be incomplete.
1: Yes, create a config.php file with the server-specific information and include it when you need it. This is incredibly common and normal. Ideally, you can keep this file a little separate from your other files so that it's easy to grab all of your application files and copy them to the live server without also copying the config file. Keep a backup of your live config file somewhere, because one day you will overwrite it, and it's much better for your heart if you don't have to scramble to figure out what the live database password was.
2: There are some automated ways of handling this, but they're very complicated. What I usually do is create an empty text file named changes.sql or something. As I make changes to the dev database, I paste the CREATE TABLE and ALTER TABLE, etc. queries into the changes.sql file. This way I have one file with all the changes I need to make to the live server when I'm ready to update the live site. After I do the update, I save the changes.sql file somewhere and create a new empty file for the next changes.
More 2: You can also just do a dump of the whole dev database and copy it live. Most sites, though, have data on the live server that should not be destroyed or copied to dev - user information, orders, login tracking, user comments, whatever. So you generally do no not want to just replace all your live data with dev data.
I usually keep the template stuff separate from the db connection, global variable stuff, and session stuff with an include file like 'init.php' or 'config.php'. When you update your stuff, most likely you won't need to overwrite that file.
I use linux, so I use 'mysqldump' to get a .sql file, upload to server, then just upload 'mysql -u user -p databasename < database.sql'. It would be great if there was a quicker way that I don't know of.
I am trying to figure out how one would start the setup of a small CMS.
I have the groundwork built, but the step of creating the database tables in mysql, should this all be done at once in a install.php file? Is there a preferred method for creating many tables at once, even if I don't need to insert data into them at this time?
You can
Import the schema file to your database prior to deploying the application
You can have a script that creates the schema
You can have a script that makes any changes to the current schema (for upgrades)
For a small CMS, I'd just keep the SQL in a schema file and import it when I need it.
You could also do a database copy from your dev -> live system. So you make the changes in the dev database as you need them and then push them to the live database. Something like SQLCompare for SQL Server works well.
Wordpress does the install.php route, where you have to enter your credentials and such for the target database and it then pushes the changes to it.
If you're going to be distributing your application for 3rd parties to install on their own servers, a very common approach is to provide (as you said) a simple install.php file. If your application is more complicated, often times an installation directory will come packaged. The user installing the application opens this in a browser, where your script typically does a few things:
Check PHP installation - verify (using function_exists()) all the required functions (and thus libraries) are installed and available. Alert the user of anything missing.
Allow the user to enter their configuration parameters - application specific settings required. Typically database hostname, username & password.
Test database connection - if successful, load initial tables. Commonly you keep your base schema file stored as a SQL file, so the application pushes this through the native mysql client, or issues the individual SQL commands directly.