I apologize in advance if this turns out to be a stupid question, but I've been racking my brain for an hour already.
I normally work in PHP with Laravel, but now I've been plunged into a project that uses a Wordpress database and a custom framework which uses PDO queries directly from the controller (no models exist); I need help figuring something out since I'm very inexperienced in Wordpress and PDO.
The client gave me a link to a database named simb2317419733, it has a Wordpress structure and the prefix is wp_wd5t1y9832_.
However, the queries on the site seem to reference tables that don't exist in this database. For example, the following query is trying to insert into a table named answers but:
1) no such table exists in the database
2) no error is thrown
Here is the query info:
http://pastebin.com/n08LnFbK
Notice that all the info matches the database above (host, user, password, prefix) but the database name itself is just wordpress. Is this a normal occurrence in Wordpress, or is this a case of the client simply giving me the wrong database which happens to have the same prefix? Or is the answers table missing but PDO isn't reporting the error for some reason?
Check that plugin how it creates the connection to database. There are two options: or it connects to the same database like the whole worpdress using constants from wp_config file, or there is plugin configuration, where you can provide different connection details. It can be either set in wp admin panel or some config files... But if you figure out, that it is using the same database, then there are two options. As you said, you've received wrong information. The second: plugin is not installed and it hasn't set up its tables.
Related
I am working on a project for a Database Systems class where we created a database and have to present it somehow. Our group had the idea to create an 'imdb' type website where various information about movies could be stored and presented to the user. We have our database created and are about to begin work on the front-end for the website.
We have some confusion among our group as to how to proceed. We understand that we need to use PHP to connect to the database with the username and password credentials, but from there:
Do you have to have the PHP connection code on every webpage, or just the home page?
What do the queries look like when communicating with the database to retrieve and display data?
Would a WordPress site be easier to use when working in this capacity as it's more or less a 'Proof of Concept' type project, not a fully fleshed out site?
As itoctopus said, every page will need to connect to the database. I have found the easiest way to accomplish this is to build your db connection in a "header" file (a file that is "included" in every php that needs access to the db).
Here are your answers:
Yes- you will need to have the connection on every page. Usually, the connection parameters and script is located in one file which you require on every page.
A query looks like:
SELECT `name` FROM `movies` ORDER BY ID DESC LIMIT 0, 10;
You may find some WordPress plugins which will do something similar. If it's a proof of concept, then I suggest you go this way (if such a plugin exists). It's also a good idea to read extensively on PHP/MySQL development or hire someone who can do that if you want to make that project real.
I have just transferred a backup of a WordPress site to a new domain. I loaded all of the sites files using FTP and I connected the main database (called boxedsco_master.sql) to the new site's database using phpMyAdmin. The new prefix for the databases is "boxeipxy_" rather than "boxedsco_". I also updated wp-config.php to connect the master database, which worked fine.
However there was also a second database called boxedsco_boxes.sql. Which I also uploaded using phpMyAdmin, and is now called "boxeipxy_boxes.sql".
The site is mainly working, however, there are no notification emails when an order is placed, either to me customer or my client. I believe this could be because the second database is not correctly connected, as the database contains tables called things like "wp_easycontactforms_customforms".
How do I connect this second database? Would there be a php file to update with the new database name? I can't find a php file that references "boxedsco_boxes.sql" in order to update it?
Using Wordpress 3.8.5 and WooCommerce 2.0.20
No wonder no-one responded! There should not be 2 databases! I thought it was very strange!
The email notifications issue was a bug with woocommerce not liking the send-from address! Changing it to "wordpress#[yourdomain].com" fixed the issue completely!
Thanks anyway folks!
the fact that you have a two files with .sql suffixes doesn't mean there are two databases. Crack open the files and look inside. They are most likely two dumps from the same database; have a look if they contain the same data and/or tables or not.
As the philosopher says, "a poem about the moon is not moon". A sqldump isn't a database, it's a "representation" of a database. Most likely you have two poems about the same moon.
So I have an old website which was coded over an extended period of time but has been inactive for 3 or so years. I have the full PHP source to the site, but the problem is I do not have a backup of the database any longer. I'm wondering what the best solution to recreating the database would be? It is a large site so manually going through each PHP file and trying to keep track of which tables are referenced is no small task. I've tried googling for the answer but have had no luck. Does anyone know of any tools that are available to help extract this information from the PHP and at least give me the basis of a database skeleton? Otherwise, has anyone ever had to do this? Any tips to help me along and possibly speed up the process? It is a mySQL database I'm trying to use.
The way I would do it:
Write a subset of SQLi or whatever interface was used to access the DB to intercept all DB accesses.
Replace all DB accesses with the dummy version of yours.
The basic idea is to emulate the DB so that the PHP code runs long enough to activate the various DB accesses, which in turn will allow you to analyze the way the DB is built and used.
From within these dummy functions:
print the SQL code used
regenerate just enough dummy results to let the rest of the code run, based on the tables and fields mentioned in the query parameters and the PHP code that retrieves them (you won't learn much from a SELECT *, but you can see what fields the PHP code expects to get from it)
once you have understood enough of the DB structure, recreate the tables and let the original code work on them little by little
have the previous designer flogged to death for not having provided a way to recreate the DB programatically
There are currently two answers based on the information you provided.
1) you can't do this
PHP is a typeless language. you could check you sql statements for finding field and table names. but it will not complete. if there is a select * from table, you can't see the fields. so you need to check there php accesses the fields. maybe by name or by index. you could be happy if this is done by name, because you can extract the name of the fields. finally the data types will missing. also missing: where are is an index on, what are primary keys, constrains etc.
2) easy, yes you can!
because your php is using a modern framework with contains a orm. this created the database for you. a meta information are included in the php classes/design.
just check the manual how to recreate the database.
I'm trying to do some migrations from an old site to a new site. The old site uses MySQL and the new site uses PostgreSQL. My problem is I wrote a migration script in PHP that queries info from the old DB so that I can insert them into the new DB within that same script. The reason I need the script is I have to call other functions that do things and manipulate the data since the table columns aren't a one for one match so I can't just do a backup and restore type situation. I have a class for both DB's that I use.
The mysql queries work but postgres' don't. They get error messages saying pg_query(): 19 is not a valid PostgreSQL link resource in xxx
So is it possible to run them both in the same script? If I call the two scripts separately it works ok but I can't get the data from the old server to the new one.
I've looked everywhere and don't see many questions needing to use both DB's in one file.
Any help would be cool.
You are using the same variable for both resources and passing the mysql resource to the postgresql function
I have a site under drupal (using mysql) but need it to read from a external sql database and make quires/reports, maybe using views2?
Is is at all possible? I been looking for a solution to just read (not import, its thousands of entries...) from an external database for hours and not sure if its even possible.
Drupal can access external databases, assuming that they are one of the types Drupal supports.
I will refer you to this handbook page: How to connect to multiple databases within Drupal.
However, to actually access data in the external database, you will need to write custom code, probably in a custom module. Essentially, you will need to do something like:
// Set Database API to use the other database.
db_set_active('external_db');
// Query the database.
db_query("SELECT * FROM {your_table} WHERE condition = 'value'");
// Set the Database API back to the default db.
db_set_active('default');
Essentially, point the database to the external database, make your reads and writes, and switch back. If you forget to switch back, Drupal will crash as it's core functions will try to work with the non-Drupal database.
It's possible to define several database connections in your settings.php and use db_set_active to select which database to use.
If you want to do this with views, you might need to do some extra work and embed the view after setting the active database to the external one.
Without writing code, you should be able to create views of the secondary database using the Table Wizard module. However, given how Drupal 6 handles its database abstraction, this will require that the secondary database be the same type as the main Drupal database (eg, either both are MySQL or both are Postgresql).