0

I'm using mysql_connect() to get $thread_id for using with next query. but I read from php.net that mysql_connect() is deprecated as of PHP 5.5.0. I tested and found found out the $thread_id is not working with the mysqli_connect().

mysql_connect: Opens or reuses a connection to a MySQL server.

mysqli_connect: Opens a connection to the MySQL Server running on.

currently, my working code is:

$link = mysql_connect($this->_wpdb->dbhost, $this->_wpdb->dbuser, $this->_wpdb->dbpassword);
$thread_id = mysql_thread_id($link);

when mysql_connect() get removed in the future, how can I change my code to work with mysqli ?

Community
  • 1
  • 1
Jenny
  • 1,729
  • 4
  • 19
  • 37
  • 1
    possible duplicate of [Converting mysql to mysqli - how to get superglobal connection object?](http://stackoverflow.com/questions/487375/converting-mysql-to-mysqli-how-to-get-superglobal-connection-object) – Shankar Narayana Damodaran Mar 11 '14 at 04:30
  • *"`$thread_id` is not working with the `mysqli_connect()`"* - I think you meant `mysql_thread_id()` is not working with the `mysqli_connect()` - That's because those are two different types of SQL functions. `mysql_*` and `mysqli_*` do not mix. `$thread_id` is just a variable; it doesn't know you from Adam ;-) – Funk Forty Niner Mar 11 '14 at 04:32
  • yes, and that function is going to be replaced by mysqli_thread_id(). @ShankarDamodaran , that question is not connection_id specific. – Jenny Mar 11 '14 at 04:35

1 Answers1

-1

How is this not working? mysqli.thread-id From manual about returning values:

mysql_thread_id()

The thread ID on success or FALSE on failure.

mysqli_thread_id()

Returns the Thread ID for the current connection.

sunshinejr
  • 4,834
  • 2
  • 22
  • 32
  • mysqli_thread_id() returns the thread id for the current connection. But I will use this thread id as a condition for next query. – Jenny Mar 11 '14 at 04:39
  • Both functions return the same: current thread_id. I don't understand what's wrong with it. – sunshinejr Mar 11 '14 at 04:43
  • mysqli_thread_id() doesn't return the thread_id that previously used. – Jenny Mar 11 '14 at 04:45
  • Same with mysql_thread_id(). You are assigning the `$link` to get the thread_id. `mysql_thread_id($link);` => `mysqli_thread_id($link);` – sunshinejr Mar 11 '14 at 04:47
  • this works only when you currently is queering something. but between 2 queries, it doesn't return a value. – Jenny Mar 11 '14 at 04:51
  • You didn't specified that you want it between 2 queries. Then create 2 variables, `$thread_id1` on first query and `$thread_id2` on second and use whatever you want. – sunshinejr Mar 11 '14 at 05:10