Title: connection to database doesn&#039;t work while using normal mysql codes !
Last modified: August 30, 2016

---

# connection to database doesn't work while using normal mysql codes !

 *  [zainab_d](https://wordpress.org/support/users/zainab_d/)
 * (@zainab_d)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/connection-to-database-doesnt-work-while-using-normal-mysql-codes/)
 * hello there ,
    I have something that I just notice .. I know that wordpress uses
   the codes located in ‘**wp-config.php**‘ file , to connect to a specific database,,
   the codes for specifying the host , database , user and password : define(‘DB_NAME’,‘
   db’); define(‘DB_USER’, ‘user’); define(‘DB_PASSWORD’, ‘pass’); define(‘DB_HOST’,‘
   localhost’);
 * But I just notice something ,that when I use some mysql codes in a wordpress 
   site it doesn’t work because there is no connection to any server or any database.
   
   for example in **single.php** , Im using this code :
 *     ```
       $myrows = mysql_query("SELECT * FROM wp_slides_plugin WHERE slide_name='Main' ORDER BY position ASC"); // order by
   
       while($row= mysql_fetch_array($myrows)){
       $url[]=$row['url'];
       $title[]=$row['title'];
       $link[]=$row['link'];
       }
       ```
   
 * It doesnt work unless I connect the site with the database I use , so I have 
   to add the line :
    `mysql_query("use db", mysql_connect('localhost','user','pass'));`
 * so ,I have to connect to the database twice , its not enough to use the wordpress
   codes for connection !!
 * do I have to add mysql connection line every time I want to use mysql ?
    or there
   is some way to fix this problem ?
 * Note: This problem starts when I start using ‘**MySQL “Improved” extension**‘
   in order to use **MySQLi** on easyapache . everything was working normally with
   wordpress sites before enable ‘**MySQL “Improved” extension**‘ .
    and as you 
   can see , after enable that choice , all my wordpress sites stop reading the 
   connection codes of wordpress while using mysql codes .
 * Please help me if you can ..

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [WEN Solutions](https://wordpress.org/support/users/wen-solutions/)
 * (@wen-solutions)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/connection-to-database-doesnt-work-while-using-normal-mysql-codes/#post-6705630)
 * WordPress has its own database functions to handle databases related works. Please
   us this: [https://codex.wordpress.org/Class_Reference/wpdb](https://codex.wordpress.org/Class_Reference/wpdb)
 * Thanks!
 *  Thread Starter [zainab_d](https://wordpress.org/support/users/zainab_d/)
 * (@zainab_d)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/connection-to-database-doesnt-work-while-using-normal-mysql-codes/#post-6705640)
 * ok , thank you **WEN Solutions** !
    that was very helpful …

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘connection to database doesn't work while using normal mysql codes !’
is closed to new replies.

## Tags

 * [connection](https://wordpress.org/support/topic-tag/connection/)
 * [database](https://wordpress.org/support/topic-tag/database/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [zainab_d](https://wordpress.org/support/users/zainab_d/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/connection-to-database-doesnt-work-while-using-normal-mysql-codes/#post-6705640)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
