Simples Database - php

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.

Related

Migrating Wordpress servers, same domain.. Few questions

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.

Back Up My SQL database in PHP

Hello everyone I am pretty new to php. I am trying to create a back up of my sql database and I want the back up to run on php server at the click of a button. I found some templates the issues I am having and it may be due to the wrong templates are: On most of the templates I don't where I should enter the information that is needed to make it work, for ex( host, dbname) etc another issue is I don't know if that's the only part of the code that needs to be changed. If someone could help me find a backup template and tell me step by step how to get my database to export as a file I would greatly appreciate it!sq
Use exec function to call mysqldump, a backup utility program that's bundled with every MySQL database. Pass the folder you would like the file (it will be a .sql file) to be put, and you can simply download or ftp it from there.
A simpler option is to install PHPMyAdmin and you can use it to backup any database and table.
Hope this helps.

How do I set up PHP post dates with a 1and1 database and Dreamweaver?

I'm very, very new to PHP, so please bear with me. I'd like to configure my current website (whose files I've already converted to .php, and which I work on in Dreamweaver), so that every time I upload a new file to my server, the upload date will automatically be displayed in the article (WordPress and other CMSs do this, but I don't have the time to make a WordPress template similar to my current site layout).
The problem with the database is that it's hosted at 1and1, where remote access (i.e. via Dreamweaver) isn't permitted, and I have to use phpMyAdmin at my host's website, which is ridiculously slow. Whenever I want to, for example, create a table, I have to go through a ton of slow-loading pages.
Is there any way to automate this process, at least to some degree?
You could always build a simple PHP script which connects to your database and runs an SQL query. You could then just visit the page and the query would be executed.
Here's a tutorial on writing SQL and running it with PHP if you're not sure: http://www.tizag.com/mysqlTutorial/
PHPMyAdmin has a "SQL" tab, where you can enter text commands just as if you were typing them into your local mysql command line. If you're not sure where to find it, there's an image in this (otherwise irrelevant) tutorial. You can use this to create and modify tables, and also run queries of all kinds.

php and database question

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.

Want to create a script that takes backup of entire database and downloads it

I've built a simple cms with an admin section. I want to create something like a backup system which would take a backup of the information on the website, and also a restore system which would restore backups taken. I'm assuming backups to be SQL files generated of the tables used.
I'm using PHP and MySQL here - any idea how I can do this?
One simple solution for backup:
Call mysqldump from php http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html, and save the backup file somewhere convenient.
This is a safe solution, because you have mysqldump on any mysql installation, and it's a safe way to generate a standard sql script
It's also safe to save the whole database.
Be careful with blobs, like saved images inside database
Be careful with utf-8 data
One simple solution for restore:
Restore operation can be done with the saved script.
First disable access to the the site/app.
Take down the database.
Restore the database from the script with mysqlimport http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html
Calling external applications from php:
http://php.net/manual/en/book.exec.php
If linux/unix, check out "man pg_dump". It basically dumps whole databases (with all tables and table definitions), e.g. "pg_dump mydb > db.sql"
Create a script that calls mysqldump
Is it just for yourself or do you want it as a feature of the CMS?
I would advise using MySQL Administrator from www.mysql.com to create backups. It's a very useful tool which you can use to schedule backups from external databases you have access to. It allows you to restore to and be selective over which tables.
If it's for a feature of the CMS then a) I'm not sure that's a great plan and b) one of the above should do it!
for the backup part you can use a ready solution. check out astrails-safe for mysql/pgsql/plain_files/subversion backup with encryption and upload to S3/SFTP.
shouldn't be too hard to add the restore capability (basically just decrypt, decompress, and pipe data to the appropriate command). for mysql (w/o the encryption):
zcat -d mysqldump-blog.090820-0000.sql.gz | mysql database_name

Categories