I don’t know why the mysql_connect isn’t working inside WordPress. But an easier way of doing it would be to use the $wpdb class. Try replacing your code with this:
$second_db = new $wpdb( 'user', 'pass', 'dbname', 'host' );
$q = $second_db->get_results( 'SELECT * FROM vars' );
var_dump( $q );
and see if you get the results you want. (note that the order of the variables passed to the $wpdb
constructor is different from the order used by mysql_connect
)
Related Posts:
- get_results using wpdb
- Count & Display Database Queries
- Export wordpress table to excel
- How best to inject ads between posts in the loop?
- Change SQL get_results to search for posts with custom term in custom taxonomy
- Change all http to https in mysql databse?
- WooCommerce – Query for ordered products
- PHP variable in WordPress database query
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Query WordPress database by registered date and role
- How to prevent WordPress from retrieving data for the last 10 posts in the database?
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- Select Multiple meta_value from WP DB; Single Query
- CRUD operations using WordPress database API
- Hook directly into query execution
- Advanced SELECT query with condtional statements
- Select two sums with single get_var statement
- Replace/Mute/Stop Search Query
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- Undefined Variable: mysqli error when connecting to database
- cache specific data?
- How Can I Put Meta_Compare in the Database-Query?
- How to paginate information obtained from a query to a custom table?
- Historic WordPress database connection
- Check if an option exists and get its value in one hit
- Query multiple tables at once?
- How to get nav_menu_item_id and slug from wp database
- $wpdb->query can’t insert data
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- How to display content from external db with relevant urls
- Connecting to a different database
- SQL query to set posts in bulk based on the post content
- Query Column of Specific ID from Database Table
- Custom search query by category id
- How to display data from db in select list [closed]
- How can I query the db to access current post information?
- Compare User meta_value with Product meta_value
- How to insert a value to decimal type field using wpdb->prepare?
- Join Query on WP_USERMETA Table
- Insert NULL value using prepare()
- Job and Employee Performance Tracking with Product Safety
- WordPress Database Query works in phpMyAdmin but not in the code
- wpdb query to insert images in to post/page gallery
- Set SQL_BIG_SELECTS and MAX_JOIN_SIZE on a WP_Query
- Performance bug – slow DB query
- How to optimise this database query?
- How can we speed up wp_get_nav_menu_items()?
- Extracted CSV as Array for Custom Query Loop
- Should I Use only wpdb Class to Write Custom Queries?
- Generating an HTML table from an array based on dynamic key values
- Pulling values from a sepcific row in table
- Using class id from array for query
- database search feature
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- SQL query to rewrite all media URLs to end with .webp
- How do I find users by password?
- What is this JavaScript “require”?
- How can I make updates to a site, on a development copy, but then move updates back without overriding live site’s evolving database?
- How can I make a WordPress database portable and url independent?
- wpdb->insert multiple record at once
- How to migrate a HTTPS WordPress installation to localhost?
- How to monitor server for error establishing a database connection
- Default WordPress settings API data sanitization
- Fatal error: Call to undefined function dbDelta()
- Connect to remote database using Localhost install
- remove missing image attachments
- How to ensure data consistency in WordPress
- How to intercept update_option() before it saves data?
- wpdb query on custom table not working [closed]
- How to fix unchanged URLs in Database after running serialized search and replace script?
- wp_redirection_404 table has grown to 7GB
- Delete all post meta except featured image Using SQL
- Adding new row to wp_post table
- How to interact with another wordpress install on same database?
- Saving into post_excerpt or post_content
- Maintain user profile data in a non-WordPress database
- Setup private content for specific users with daily updates [closed]
- Connection refused on locahost after importing database?
- Custom page with queries returns 404
- WSOD 3.9.1 – Tried Everything so far
- Sending posts from Python to WordPress
- Problem migrating to localhost
- Automate WordPress website setup with prefilled data
- How do you render posts from outside wordpress?
- Second ezSQL initialization for MSSQL
- Fetch a single row from a custom table for to a given ID
- Database create or redirect
- Database structure cheatsheet
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- error establishing database connection (WAMP + filezilla)
- Is there a way for two deferent themes to consume two different DB on a same WP instance?
- Auto populate form fields based on serial input or pull listings from other websites?
- How to extract some part of WordPress full source code
- Error establishing a database connection for some files
- Hash user emails in database?
- Weird characters in title if it contain “ ”
- Saving data to database and exporting to excel
- One information repeated on multiple locations on one site [closed]
- Showing Error(TAble already exist)